Skip to content

Commit f16a957

Browse files
fthaingeertu
authored andcommitted
nubus: Call put_device() in bus initialization error path
The error path for bus initialization is missing a call to put_device(). Add that call. This error path will probably never actually execute, but any kernel source code may be subject to static checking or re-use. Cc: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn> Cc: Daniel Palmer <daniel@0x0f.com> Suggested-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn> Signed-off-by: Finn Thain <fthain@linux-m68k.org> Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org> Link: https://patch.msgid.link/478d5f080d74b6688c9e3f9132e3fe251e997ad7.1765610469.git.fthain@linux-m68k.org Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
1 parent 8f0b4cc commit f16a957

3 files changed

Lines changed: 12 additions & 16 deletions

File tree

drivers/nubus/bus.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,12 @@ void nubus_driver_unregister(struct nubus_driver *ndrv)
5151
}
5252
EXPORT_SYMBOL(nubus_driver_unregister);
5353

54-
static struct device nubus_parent = {
55-
.init_name = "nubus",
56-
};
57-
5854
static int __init nubus_bus_register(void)
5955
{
6056
return bus_register(&nubus_bus_type);
6157
}
6258
postcore_initcall(nubus_bus_register);
6359

64-
int __init nubus_parent_device_register(void)
65-
{
66-
return device_register(&nubus_parent);
67-
}
68-
6960
static void nubus_device_release(struct device *dev)
7061
{
7162
struct nubus_board *board = to_nubus_board(dev);
@@ -79,9 +70,9 @@ static void nubus_device_release(struct device *dev)
7970
kfree(board);
8071
}
8172

82-
int nubus_device_register(struct nubus_board *board)
73+
int nubus_device_register(struct device *parent, struct nubus_board *board)
8374
{
84-
board->dev.parent = &nubus_parent;
75+
board->dev.parent = parent;
8576
board->dev.release = nubus_device_release;
8677
board->dev.bus = &nubus_bus_type;
8778
dev_set_name(&board->dev, "slot.%X", board->slot);

drivers/nubus/nubus.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ module_param_named(populate_procfs, nubus_populate_procfs, bool, 0);
4141

4242
LIST_HEAD(nubus_func_rsrcs);
4343

44+
static struct device nubus_parent = {
45+
.init_name = "nubus",
46+
};
47+
4448
/* Meaning of "bytelanes":
4549
4650
The card ROM may appear on any or all bytes of each long word in
@@ -829,7 +833,7 @@ static void __init nubus_add_board(int slot, int bytelanes)
829833
list_add_tail(&fres->list, &nubus_func_rsrcs);
830834
}
831835

832-
if (nubus_device_register(board))
836+
if (nubus_device_register(&nubus_parent, board))
833837
put_device(&board->dev);
834838
}
835839

@@ -882,9 +886,11 @@ static int __init nubus_init(void)
882886
return 0;
883887

884888
nubus_proc_init();
885-
err = nubus_parent_device_register();
886-
if (err)
889+
err = device_register(&nubus_parent);
890+
if (err) {
891+
put_device(&nubus_parent);
887892
return err;
893+
}
888894
nubus_scan_bus();
889895
return 0;
890896
}

include/linux/nubus.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ void nubus_seq_write_rsrc_mem(struct seq_file *m,
162162
unsigned char *nubus_dirptr(const struct nubus_dirent *nd);
163163

164164
/* Declarations relating to driver model objects */
165-
int nubus_parent_device_register(void);
166-
int nubus_device_register(struct nubus_board *board);
165+
int nubus_device_register(struct device *parent, struct nubus_board *board);
167166
int nubus_driver_register(struct nubus_driver *ndrv);
168167
void nubus_driver_unregister(struct nubus_driver *ndrv);
169168
int nubus_proc_show(struct seq_file *m, void *data);

0 commit comments

Comments
 (0)