Skip to content

Commit 723de0f

Browse files
cgrogregkh
authored andcommitted
staging: most: remove device from interface structure
This patch makes the adapter drivers use their own device structures when registering a most interface with the core module. With this the module that actually operates the physical device is the owner of the device. 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 2893c67 commit 723de0f

File tree

4 files changed

+38
-33
lines changed

4 files changed

+38
-33
lines changed

drivers/staging/most/core.c

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ static ssize_t description_show(struct device *dev,
402402
struct device_attribute *attr,
403403
char *buf)
404404
{
405-
struct most_interface *iface = to_most_interface(dev);
405+
struct most_interface *iface = dev_get_drvdata(dev);
406406

407407
return snprintf(buf, PAGE_SIZE, "%s\n", iface->description);
408408
}
@@ -411,7 +411,7 @@ static ssize_t interface_show(struct device *dev,
411411
struct device_attribute *attr,
412412
char *buf)
413413
{
414-
struct most_interface *iface = to_most_interface(dev);
414+
struct most_interface *iface = dev_get_drvdata(dev);
415415

416416
switch (iface->interface) {
417417
case ITYPE_LOOPBACK:
@@ -476,23 +476,23 @@ static int print_links(struct device *dev, void *data)
476476
int offs = d->offs;
477477
char *buf = d->buf;
478478
struct most_channel *c;
479-
struct most_interface *iface = to_most_interface(dev);
479+
struct most_interface *iface = dev_get_drvdata(dev);
480480

481481
list_for_each_entry(c, &iface->p->channel_list, list) {
482482
if (c->pipe0.comp) {
483483
offs += snprintf(buf + offs,
484484
PAGE_SIZE - offs,
485485
"%s:%s:%s\n",
486486
c->pipe0.comp->name,
487-
dev_name(&iface->dev),
487+
dev_name(iface->dev),
488488
dev_name(&c->dev));
489489
}
490490
if (c->pipe1.comp) {
491491
offs += snprintf(buf + offs,
492492
PAGE_SIZE - offs,
493493
"%s:%s:%s\n",
494494
c->pipe1.comp->name,
495-
dev_name(&iface->dev),
495+
dev_name(iface->dev),
496496
dev_name(&c->dev));
497497
}
498498
}
@@ -534,7 +534,7 @@ static struct most_channel *get_channel(char *mdev, char *mdev_ch)
534534
dev = bus_find_device_by_name(&mc.bus, NULL, mdev);
535535
if (!dev)
536536
return NULL;
537-
iface = to_most_interface(dev);
537+
iface = dev_get_drvdata(dev);
538538
list_for_each_entry_safe(c, tmp, &iface->p->channel_list, list) {
539539
if (!strcmp(dev_name(&c->dev), mdev_ch))
540540
return c;
@@ -1232,7 +1232,7 @@ static int disconnect_channels(struct device *dev, void *data)
12321232
struct most_channel *c, *tmp;
12331233
struct most_component *comp = data;
12341234

1235-
iface = to_most_interface(dev);
1235+
iface = dev_get_drvdata(dev);
12361236
list_for_each_entry_safe(c, tmp, &iface->p->channel_list, list) {
12371237
if (c->pipe0.comp == comp || c->pipe1.comp == comp)
12381238
comp->disconnect_channel(c->iface, c->channel_id);
@@ -1261,14 +1261,11 @@ int most_deregister_component(struct most_component *comp)
12611261
}
12621262
EXPORT_SYMBOL_GPL(most_deregister_component);
12631263

1264-
static void release_interface(struct device *dev)
1265-
{
1266-
dev_info(&mc.dev, "releasing interface dev %s...\n", dev_name(dev));
1267-
}
1268-
12691264
static void release_channel(struct device *dev)
12701265
{
1271-
dev_info(&mc.dev, "releasing channel dev %s...\n", dev_name(dev));
1266+
struct most_channel *c = to_channel(dev);
1267+
1268+
kfree(c);
12721269
}
12731270

12741271
/**
@@ -1305,14 +1302,14 @@ int most_register_interface(struct most_interface *iface)
13051302
INIT_LIST_HEAD(&iface->p->channel_list);
13061303
iface->p->dev_id = id;
13071304
strscpy(iface->p->name, iface->description, sizeof(iface->p->name));
1308-
iface->dev.init_name = iface->p->name;
1309-
iface->dev.bus = &mc.bus;
1310-
iface->dev.parent = &mc.dev;
1311-
iface->dev.groups = interface_attr_groups;
1312-
iface->dev.release = release_interface;
1313-
if (device_register(&iface->dev)) {
1305+
iface->dev->bus = &mc.bus;
1306+
iface->dev->parent = &mc.dev;
1307+
iface->dev->groups = interface_attr_groups;
1308+
dev_set_drvdata(iface->dev, iface);
1309+
if (device_register(iface->dev)) {
13141310
dev_err(&mc.dev, "registering iface->dev failed\n");
13151311
kfree(iface->p);
1312+
put_device(iface->dev);
13161313
ida_simple_remove(&mdev_id, id);
13171314
return -ENOMEM;
13181315
}
@@ -1328,7 +1325,7 @@ int most_register_interface(struct most_interface *iface)
13281325
else
13291326
snprintf(c->name, STRING_SIZE, "%s", name_suffix);
13301327
c->dev.init_name = c->name;
1331-
c->dev.parent = &iface->dev;
1328+
c->dev.parent = iface->dev;
13321329
c->dev.groups = channel_attr_groups;
13331330
c->dev.release = release_channel;
13341331
iface->p->channel[i] = c;
@@ -1362,16 +1359,15 @@ int most_register_interface(struct most_interface *iface)
13621359
return 0;
13631360

13641361
err_free_most_channel:
1365-
kfree(c);
1362+
put_device(&c->dev);
13661363

13671364
err_free_resources:
13681365
while (i > 0) {
13691366
c = iface->p->channel[--i];
13701367
device_unregister(&c->dev);
1371-
kfree(c);
13721368
}
13731369
kfree(iface->p);
1374-
device_unregister(&iface->dev);
1370+
device_unregister(iface->dev);
13751371
ida_simple_remove(&mdev_id, id);
13761372
return -ENOMEM;
13771373
}
@@ -1401,12 +1397,11 @@ void most_deregister_interface(struct most_interface *iface)
14011397
c->pipe1.comp = NULL;
14021398
list_del(&c->list);
14031399
device_unregister(&c->dev);
1404-
kfree(c);
14051400
}
14061401

14071402
ida_simple_remove(&mdev_id, iface->p->dev_id);
14081403
kfree(iface->p);
1409-
device_unregister(&iface->dev);
1404+
device_unregister(iface->dev);
14101405
}
14111406
EXPORT_SYMBOL_GPL(most_deregister_interface);
14121407

drivers/staging/most/dim2/dim2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,8 +854,8 @@ static int dim2_probe(struct platform_device *pdev)
854854
dev->most_iface.poison_channel = poison_channel;
855855
dev->most_iface.request_netinfo = request_netinfo;
856856
dev->most_iface.driver_dev = &pdev->dev;
857+
dev->most_iface.dev = &dev->dev;
857858
dev->dev.init_name = "dim2_state";
858-
dev->dev.parent = &dev->most_iface.dev;
859859

860860
ret = most_register_interface(&dev->most_iface);
861861
if (ret) {

drivers/staging/most/most.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ struct mbo {
229229
* @priv Private field used by mostcore to store context information.
230230
*/
231231
struct most_interface {
232-
struct device dev;
232+
struct device *dev;
233233
struct device *driver_dev;
234234
struct module *mod;
235235
enum most_interface_type interface;
@@ -251,8 +251,6 @@ struct most_interface {
251251
struct interface_private *p;
252252
};
253253

254-
#define to_most_interface(d) container_of(d, struct most_interface, dev)
255-
256254
/**
257255
* struct most_component - identifies a loadable component for the mostcore
258256
* @list: list_head

drivers/staging/most/usb/usb.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ struct clear_hold_work {
102102
* @poll_work_obj: work for polling link status
103103
*/
104104
struct most_dev {
105+
struct device dev;
105106
struct usb_device *usb_device;
106107
struct most_interface iface;
107108
struct most_channel_capability *cap;
@@ -123,6 +124,7 @@ struct most_dev {
123124
};
124125

125126
#define to_mdev(d) container_of(d, struct most_dev, iface)
127+
#define to_mdev_from_dev(d) container_of(d, struct most_dev, dev)
126128
#define to_mdev_from_work(w) container_of(w, struct most_dev, poll_work_obj)
127129

128130
static void wq_clear_halt(struct work_struct *wq_obj);
@@ -1023,6 +1025,12 @@ static void release_dci(struct device *dev)
10231025
kfree(dci);
10241026
}
10251027

1028+
static void release_mdev(struct device *dev)
1029+
{
1030+
struct most_dev *mdev = to_mdev_from_dev(dev);
1031+
1032+
kfree(mdev);
1033+
}
10261034
/**
10271035
* hdm_probe - probe function of USB device driver
10281036
* @interface: Interface of the attached USB device
@@ -1061,6 +1069,7 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
10611069
mdev->link_stat_timer.expires = jiffies + (2 * HZ);
10621070

10631071
mdev->iface.mod = hdm_usb_fops.owner;
1072+
mdev->iface.dev = &mdev->dev;
10641073
mdev->iface.driver_dev = &interface->dev;
10651074
mdev->iface.interface = ITYPE_USB;
10661075
mdev->iface.configure = hdm_configure_channel;
@@ -1079,6 +1088,9 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
10791088
usb_dev->config->desc.bConfigurationValue,
10801089
usb_iface_desc->desc.bInterfaceNumber);
10811090

1091+
mdev->dev.init_name = mdev->description;
1092+
mdev->dev.parent = &interface->dev;
1093+
mdev->dev.release = release_mdev;
10821094
mdev->conf = kcalloc(num_endpoints, sizeof(*mdev->conf), GFP_KERNEL);
10831095
if (!mdev->conf)
10841096
goto err_free_mdev;
@@ -1152,7 +1164,7 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
11521164
}
11531165

11541166
mdev->dci->dev.init_name = "dci";
1155-
mdev->dci->dev.parent = &mdev->iface.dev;
1167+
mdev->dci->dev.parent = get_device(mdev->iface.dev);
11561168
mdev->dci->dev.groups = dci_attr_groups;
11571169
mdev->dci->dev.release = release_dci;
11581170
if (device_register(&mdev->dci->dev)) {
@@ -1166,7 +1178,7 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
11661178
mutex_unlock(&mdev->io_mutex);
11671179
return 0;
11681180
err_free_dci:
1169-
kfree(mdev->dci);
1181+
put_device(&mdev->dci->dev);
11701182
err_free_busy_urbs:
11711183
kfree(mdev->busy_urbs);
11721184
err_free_ep_address:
@@ -1176,7 +1188,7 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
11761188
err_free_conf:
11771189
kfree(mdev->conf);
11781190
err_free_mdev:
1179-
kfree(mdev);
1191+
put_device(&mdev->dev);
11801192
err_out_of_memory:
11811193
if (ret == 0 || ret == -ENOMEM) {
11821194
ret = -ENOMEM;
@@ -1213,7 +1225,7 @@ static void hdm_disconnect(struct usb_interface *interface)
12131225
kfree(mdev->cap);
12141226
kfree(mdev->conf);
12151227
kfree(mdev->ep_address);
1216-
kfree(mdev);
1228+
put_device(&mdev->dev);
12171229
}
12181230

12191231
static struct usb_driver hdm_usb = {

0 commit comments

Comments
 (0)