Skip to content

Commit 6cda08a

Browse files
Suzuki K Poulosegregkh
authored andcommitted
drivers: Introduce device lookup variants by name
Add a helper to match the device name for device lookup. Also reuse this generic exported helper for the existing bus_find_device_by_name(). and add similar variants for driver/class. Cc: Alessandro Zummo <a.zummo@towertech.it> Cc: Alexander Aring <alex.aring@gmail.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Dan Murphy <dmurphy@ti.com> Cc: Harald Freudenberger <freude@linux.ibm.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com> Cc: Lee Jones <lee.jones@linaro.org> Cc: linux-leds@vger.kernel.org Cc: linux-rtc@vger.kernel.org Cc: linux-usb@vger.kernel.org Cc: linux-wpan@vger.kernel.org Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com> Cc: Pavel Machek <pavel@ucw.cz> Cc: Peter Oberparleiter <oberpar@linux.ibm.com> Cc: "Rafael J. Wysocki" <rafael@kernel.org> Cc: Stefan Schmidt <stefan@datenfreihafen.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20190723221838.12024-2-suzuki.poulose@arm.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5f9e832 commit 6cda08a

12 files changed

Lines changed: 54 additions & 106 deletions

File tree

‎drivers/base/bus.c‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -342,30 +342,6 @@ struct device *bus_find_device(struct bus_type *bus,
342342
}
343343
EXPORT_SYMBOL_GPL(bus_find_device);
344344

345-
static int match_name(struct device *dev, const void *data)
346-
{
347-
const char *name = data;
348-
349-
return sysfs_streq(name, dev_name(dev));
350-
}
351-
352-
/**
353-
* bus_find_device_by_name - device iterator for locating a particular device of a specific name
354-
* @bus: bus type
355-
* @start: Device to begin with
356-
* @name: name of the device to match
357-
*
358-
* This is similar to the bus_find_device() function above, but it handles
359-
* searching by a name automatically, no need to write another strcmp matching
360-
* function.
361-
*/
362-
struct device *bus_find_device_by_name(struct bus_type *bus,
363-
struct device *start, const char *name)
364-
{
365-
return bus_find_device(bus, start, (void *)name, match_name);
366-
}
367-
EXPORT_SYMBOL_GPL(bus_find_device_by_name);
368-
369345
/**
370346
* subsys_find_device_by_id - find a device with a specific enumeration number
371347
* @subsys: subsystem

‎drivers/base/core.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3357,6 +3357,12 @@ void device_set_of_node_from_dev(struct device *dev, const struct device *dev2)
33573357
}
33583358
EXPORT_SYMBOL_GPL(device_set_of_node_from_dev);
33593359

3360+
int device_match_name(struct device *dev, const void *name)
3361+
{
3362+
return sysfs_streq(dev_name(dev), name);
3363+
}
3364+
EXPORT_SYMBOL_GPL(device_match_name);
3365+
33603366
int device_match_of_node(struct device *dev, const void *np)
33613367
{
33623368
return dev->of_node == np;

‎drivers/hwtracing/stm/core.c‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,6 @@ static struct class stm_class = {
8989
.dev_groups = stm_groups,
9090
};
9191

92-
static int stm_dev_match(struct device *dev, const void *data)
93-
{
94-
const char *name = data;
95-
96-
return sysfs_streq(name, dev_name(dev));
97-
}
98-
9992
/**
10093
* stm_find_device() - find stm device by name
10194
* @buf: character buffer containing the name
@@ -116,7 +109,7 @@ struct stm_device *stm_find_device(const char *buf)
116109
if (!stm_core_up)
117110
return NULL;
118111

119-
dev = class_find_device(&stm_class, NULL, buf, stm_dev_match);
112+
dev = class_find_device_by_name(&stm_class, buf);
120113
if (!dev)
121114
return NULL;
122115

‎drivers/leds/led-class.c‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,6 @@ static int led_resume(struct device *dev)
213213

214214
static SIMPLE_DEV_PM_OPS(leds_class_dev_pm_ops, led_suspend, led_resume);
215215

216-
static int match_name(struct device *dev, const void *data)
217-
{
218-
if (!dev_name(dev))
219-
return 0;
220-
return !strcmp(dev_name(dev), (char *)data);
221-
}
222-
223216
static int led_classdev_next_name(const char *init_name, char *name,
224217
size_t len)
225218
{
@@ -230,7 +223,7 @@ static int led_classdev_next_name(const char *init_name, char *name,
230223
strlcpy(name, init_name, len);
231224

232225
while ((ret < len) &&
233-
(dev = class_find_device(leds_class, NULL, name, match_name))) {
226+
(dev = class_find_device_by_name(leds_class, name))) {
234227
put_device(dev);
235228
ret = snprintf(name, len, "%s_%u", init_name, ++i);
236229
}

‎drivers/rtc/interface.c‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -663,21 +663,12 @@ void rtc_update_irq(struct rtc_device *rtc,
663663
}
664664
EXPORT_SYMBOL_GPL(rtc_update_irq);
665665

666-
static int __rtc_match(struct device *dev, const void *data)
667-
{
668-
const char *name = data;
669-
670-
if (strcmp(dev_name(dev), name) == 0)
671-
return 1;
672-
return 0;
673-
}
674-
675666
struct rtc_device *rtc_class_open(const char *name)
676667
{
677668
struct device *dev;
678669
struct rtc_device *rtc = NULL;
679670

680-
dev = class_find_device(rtc_class, NULL, name, __rtc_match);
671+
dev = class_find_device_by_name(rtc_class, name);
681672
if (dev)
682673
rtc = to_rtc_device(dev);
683674

‎drivers/s390/cio/ccwgroup.c‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -608,13 +608,6 @@ void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver)
608608
}
609609
EXPORT_SYMBOL(ccwgroup_driver_unregister);
610610

611-
static int __ccwgroupdev_check_busid(struct device *dev, const void *id)
612-
{
613-
const char *bus_id = id;
614-
615-
return (strcmp(bus_id, dev_name(dev)) == 0);
616-
}
617-
618611
/**
619612
* get_ccwgroupdev_by_busid() - obtain device from a bus id
620613
* @gdrv: driver the device is owned by
@@ -631,8 +624,7 @@ struct ccwgroup_device *get_ccwgroupdev_by_busid(struct ccwgroup_driver *gdrv,
631624
{
632625
struct device *dev;
633626

634-
dev = driver_find_device(&gdrv->driver, NULL, bus_id,
635-
__ccwgroupdev_check_busid);
627+
dev = driver_find_device_by_name(&gdrv->driver, bus_id);
636628

637629
return dev ? to_ccwgroupdev(dev) : NULL;
638630
}

‎drivers/s390/cio/device.c‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,18 +1695,6 @@ int ccw_device_force_console(struct ccw_device *cdev)
16951695
EXPORT_SYMBOL_GPL(ccw_device_force_console);
16961696
#endif
16971697

1698-
/*
1699-
* get ccw_device matching the busid, but only if owned by cdrv
1700-
*/
1701-
static int
1702-
__ccwdev_check_busid(struct device *dev, const void *id)
1703-
{
1704-
const char *bus_id = id;
1705-
1706-
return (strcmp(bus_id, dev_name(dev)) == 0);
1707-
}
1708-
1709-
17101698
/**
17111699
* get_ccwdev_by_busid() - obtain device from a bus id
17121700
* @cdrv: driver the device is owned by
@@ -1723,8 +1711,7 @@ struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv,
17231711
{
17241712
struct device *dev;
17251713

1726-
dev = driver_find_device(&cdrv->driver, NULL, (void *)bus_id,
1727-
__ccwdev_check_busid);
1714+
dev = driver_find_device_by_name(&cdrv->driver, bus_id);
17281715

17291716
return dev ? to_ccwdev(dev) : NULL;
17301717
}

‎drivers/s390/crypto/zcrypt_api.c‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,6 @@ struct zcdn_device {
133133
static int zcdn_create(const char *name);
134134
static int zcdn_destroy(const char *name);
135135

136-
/* helper function, matches the name for find_zcdndev_by_name() */
137-
static int __match_zcdn_name(struct device *dev, const void *data)
138-
{
139-
return strcmp(dev_name(dev), (const char *)data) == 0;
140-
}
141-
142136
/* helper function, matches the devt value for find_zcdndev_by_devt() */
143137
static int __match_zcdn_devt(struct device *dev, const void *data)
144138
{
@@ -152,10 +146,7 @@ static int __match_zcdn_devt(struct device *dev, const void *data)
152146
*/
153147
static inline struct zcdn_device *find_zcdndev_by_name(const char *name)
154148
{
155-
struct device *dev =
156-
class_find_device(zcrypt_class, NULL,
157-
(void *) name,
158-
__match_zcdn_name);
149+
struct device *dev = class_find_device_by_name(zcrypt_class, name);
159150

160151
return dev ? to_zcdn_dev(dev) : NULL;
161152
}

‎drivers/usb/roles/class.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ static int switch_fwnode_match(struct device *dev, const void *fwnode)
9090
return dev_fwnode(dev) == fwnode;
9191
}
9292

93-
static int switch_name_match(struct device *dev, const void *name)
94-
{
95-
return !strcmp((const char *)name, dev_name(dev));
96-
}
97-
9893
static void *usb_role_switch_match(struct device_connection *con, int ep,
9994
void *data)
10095
{
@@ -107,8 +102,7 @@ static void *usb_role_switch_match(struct device_connection *con, int ep,
107102
dev = class_find_device(role_class, NULL, con->fwnode,
108103
switch_fwnode_match);
109104
} else {
110-
dev = class_find_device(role_class, NULL, con->endpoint[ep],
111-
switch_name_match);
105+
dev = class_find_device_by_name(role_class, con->endpoint[ep]);
112106
}
113107

114108
return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);

‎drivers/usb/typec/class.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,6 @@ static int typec_port_fwnode_match(struct device *dev, const void *fwnode)
210210
return dev_fwnode(dev) == fwnode;
211211
}
212212

213-
static int typec_port_name_match(struct device *dev, const void *name)
214-
{
215-
return !strcmp((const char *)name, dev_name(dev));
216-
}
217-
218213
static void *typec_port_match(struct device_connection *con, int ep, void *data)
219214
{
220215
struct device *dev;
@@ -227,8 +222,7 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data)
227222
return class_find_device(typec_class, NULL, con->fwnode,
228223
typec_port_fwnode_match);
229224

230-
dev = class_find_device(typec_class, NULL, con->endpoint[ep],
231-
typec_port_name_match);
225+
dev = class_find_device_by_name(typec_class, con->endpoint[ep]);
232226

233227
return dev ? dev : ERR_PTR(-EPROBE_DEFER);
234228
}

0 commit comments

Comments
 (0)