Skip to content

Commit d693e90

Browse files
cgrogregkh
authored andcommitted
staging: most: core: remove container struct
This patch declares and initializes the bus, bus driver and the component list without a container struct, as it introduces an unnecessary level of abstraction. Signed-off-by: Christian Gromm <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6a82c77 commit d693e90

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

drivers/staging/most/core.c

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,7 @@
2828

2929
static struct ida mdev_id;
3030
static int dummy_num_buffers;
31-
32-
static struct mostcore {
33-
struct device_driver drv;
34-
struct bus_type bus;
35-
struct list_head comp_list;
36-
} mc;
37-
38-
#define to_driver(d) container_of(d, struct mostcore, drv)
31+
static struct list_head comp_list;
3932

4033
struct pipe {
4134
struct most_component *comp;
@@ -457,7 +450,7 @@ static struct most_component *match_component(char *name)
457450
{
458451
struct most_component *comp;
459452

460-
list_for_each_entry(comp, &mc.comp_list, list) {
453+
list_for_each_entry(comp, &comp_list, list) {
461454
if (!strcmp(comp->name, name))
462455
return comp;
463456
}
@@ -499,11 +492,24 @@ static int print_links(struct device *dev, void *data)
499492
return 0;
500493
}
501494

495+
static int most_match(struct device *dev, struct device_driver *drv)
496+
{
497+
if (!strcmp(dev_name(dev), "most"))
498+
return 0;
499+
else
500+
return 1;
501+
}
502+
503+
static struct bus_type mostbus = {
504+
.name = "most",
505+
.match = most_match,
506+
};
507+
502508
static ssize_t links_show(struct device_driver *drv, char *buf)
503509
{
504510
struct show_links_data d = { .buf = buf };
505511

506-
bus_for_each_dev(&mc.bus, NULL, &d, print_links);
512+
bus_for_each_dev(&mostbus, NULL, &d, print_links);
507513
return d.offs;
508514
}
509515

@@ -512,7 +518,7 @@ static ssize_t components_show(struct device_driver *drv, char *buf)
512518
struct most_component *comp;
513519
int offs = 0;
514520

515-
list_for_each_entry(comp, &mc.comp_list, list) {
521+
list_for_each_entry(comp, &comp_list, list) {
516522
offs += snprintf(buf + offs, PAGE_SIZE - offs, "%s\n",
517523
comp->name);
518524
}
@@ -530,7 +536,7 @@ static struct most_channel *get_channel(char *mdev, char *mdev_ch)
530536
struct most_interface *iface;
531537
struct most_channel *c, *tmp;
532538

533-
dev = bus_find_device_by_name(&mc.bus, NULL, mdev);
539+
dev = bus_find_device_by_name(&mostbus, NULL, mdev);
534540
if (!dev)
535541
return NULL;
536542
put_device(dev);
@@ -722,13 +728,11 @@ static const struct attribute_group *mc_attr_groups[] = {
722728
NULL,
723729
};
724730

725-
static int most_match(struct device *dev, struct device_driver *drv)
726-
{
727-
if (!strcmp(dev_name(dev), "most"))
728-
return 0;
729-
else
730-
return 1;
731-
}
731+
static struct device_driver mostbus_driver = {
732+
.name = "most_core",
733+
.bus = &mostbus,
734+
.groups = mc_attr_groups,
735+
};
732736

733737
static inline void trash_mbo(struct mbo *mbo)
734738
{
@@ -1221,7 +1225,7 @@ int most_register_component(struct most_component *comp)
12211225
pr_err("Bad component\n");
12221226
return -EINVAL;
12231227
}
1224-
list_add_tail(&comp->list, &mc.comp_list);
1228+
list_add_tail(&comp->list, &comp_list);
12251229
return 0;
12261230
}
12271231
EXPORT_SYMBOL_GPL(most_register_component);
@@ -1255,7 +1259,7 @@ int most_deregister_component(struct most_component *comp)
12551259
return -EINVAL;
12561260
}
12571261

1258-
bus_for_each_dev(&mc.bus, NULL, comp, disconnect_channels);
1262+
bus_for_each_dev(&mostbus, NULL, comp, disconnect_channels);
12591263
list_del(&comp->list);
12601264
return 0;
12611265
}
@@ -1302,7 +1306,7 @@ int most_register_interface(struct most_interface *iface)
13021306
INIT_LIST_HEAD(&iface->p->channel_list);
13031307
iface->p->dev_id = id;
13041308
strscpy(iface->p->name, iface->description, sizeof(iface->p->name));
1305-
iface->dev->bus = &mc.bus;
1309+
iface->dev->bus = &mostbus;
13061310
iface->dev->groups = interface_attr_groups;
13071311
dev_set_drvdata(iface->dev, iface);
13081312
if (device_register(iface->dev)) {
@@ -1454,21 +1458,15 @@ static int __init most_init(void)
14541458
{
14551459
int err;
14561460

1457-
INIT_LIST_HEAD(&mc.comp_list);
1461+
INIT_LIST_HEAD(&comp_list);
14581462
ida_init(&mdev_id);
14591463

1460-
mc.bus.name = "most",
1461-
mc.bus.match = most_match,
1462-
mc.drv.name = "most_core",
1463-
mc.drv.bus = &mc.bus,
1464-
mc.drv.groups = mc_attr_groups;
1465-
1466-
err = bus_register(&mc.bus);
1464+
err = bus_register(&mostbus);
14671465
if (err) {
14681466
pr_err("Cannot register most bus\n");
14691467
return err;
14701468
}
1471-
err = driver_register(&mc.drv);
1469+
err = driver_register(&mostbus_driver);
14721470
if (err) {
14731471
pr_err("Cannot register core driver\n");
14741472
goto err_unregister_bus;
@@ -1477,14 +1475,14 @@ static int __init most_init(void)
14771475
return 0;
14781476

14791477
err_unregister_bus:
1480-
bus_unregister(&mc.bus);
1478+
bus_unregister(&mostbus);
14811479
return err;
14821480
}
14831481

14841482
static void __exit most_exit(void)
14851483
{
1486-
driver_unregister(&mc.drv);
1487-
bus_unregister(&mc.bus);
1484+
driver_unregister(&mostbus_driver);
1485+
bus_unregister(&mostbus);
14881486
ida_destroy(&mdev_id);
14891487
}
14901488

0 commit comments

Comments
 (0)