Skip to content

Commit 9f3b795

Browse files
osctobegregkh
authored andcommitted
driver-core: constify data for class_find_device()
All in-kernel users of class_find_device() don't really need mutable data for match callback. In two places (kernel/power/suspend_test.c, drivers/scsi/osd/osd_uld.c) this patch changes match callbacks to use const search data. The const is propagated to rtc_class_open() and power_supply_get_by_name() parameters. Note that there's a dev reference leak in suspend_test.c that's not touched in this patch. Signed-off-by: Michał Mirosław <[email protected]> Acked-by: Grant Likely <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 807be03 commit 9f3b795

File tree

19 files changed

+53
-64
lines changed

19 files changed

+53
-64
lines changed

drivers/base/class.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ EXPORT_SYMBOL_GPL(class_for_each_device);
420420
* code. There's no locking restriction.
421421
*/
422422
struct device *class_find_device(struct class *class, struct device *start,
423-
void *data,
424-
int (*match)(struct device *, void *))
423+
const void *data,
424+
int (*match)(struct device *, const void *))
425425
{
426426
struct class_dev_iter iter;
427427
struct device *dev;

drivers/base/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,9 +1617,9 @@ struct device *device_create(struct class *class, struct device *parent,
16171617
}
16181618
EXPORT_SYMBOL_GPL(device_create);
16191619

1620-
static int __match_devt(struct device *dev, void *data)
1620+
static int __match_devt(struct device *dev, const void *data)
16211621
{
1622-
dev_t *devt = data;
1622+
const dev_t *devt = data;
16231623

16241624
return dev->devt == *devt;
16251625
}

drivers/gpio/gpiolib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ int gpio_export(unsigned gpio, bool direction_may_change)
806806
}
807807
EXPORT_SYMBOL_GPL(gpio_export);
808808

809-
static int match_export(struct device *dev, void *data)
809+
static int match_export(struct device *dev, const void *data)
810810
{
811811
return dev_get_drvdata(dev) == data;
812812
}

drivers/isdn/mISDN/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ static struct class mISDN_class = {
168168
};
169169

170170
static int
171-
_get_mdevice(struct device *dev, void *id)
171+
_get_mdevice(struct device *dev, const void *id)
172172
{
173173
struct mISDNdevice *mdev = dev_to_mISDN(dev);
174174

175175
if (!mdev)
176176
return 0;
177-
if (mdev->id != *(u_int *)id)
177+
if (mdev->id != *(const u_int *)id)
178178
return 0;
179179
return 1;
180180
}

drivers/net/phy/mdio_bus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static struct class mdio_bus_class = {
9595

9696
#if IS_ENABLED(CONFIG_OF_MDIO)
9797
/* Helper function for of_mdio_find_bus */
98-
static int of_mdio_bus_match(struct device *dev, void *mdio_bus_np)
98+
static int of_mdio_bus_match(struct device *dev, const void *mdio_bus_np)
9999
{
100100
return dev->of_node == mdio_bus_np;
101101
}

drivers/power/power_supply_core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@ int power_supply_set_battery_charged(struct power_supply *psy)
141141
}
142142
EXPORT_SYMBOL_GPL(power_supply_set_battery_charged);
143143

144-
static int power_supply_match_device_by_name(struct device *dev, void *data)
144+
static int power_supply_match_device_by_name(struct device *dev, const void *data)
145145
{
146146
const char *name = data;
147147
struct power_supply *psy = dev_get_drvdata(dev);
148148

149149
return strcmp(psy->name, name) == 0;
150150
}
151151

152-
struct power_supply *power_supply_get_by_name(char *name)
152+
struct power_supply *power_supply_get_by_name(const char *name)
153153
{
154154
struct device *dev = class_find_device(power_supply_class, NULL, name,
155155
power_supply_match_device_by_name);

drivers/rtc/interface.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,16 +587,16 @@ void rtc_update_irq(struct rtc_device *rtc,
587587
}
588588
EXPORT_SYMBOL_GPL(rtc_update_irq);
589589

590-
static int __rtc_match(struct device *dev, void *data)
590+
static int __rtc_match(struct device *dev, const void *data)
591591
{
592-
char *name = (char *)data;
592+
const char *name = data;
593593

594594
if (strcmp(dev_name(dev), name) == 0)
595595
return 1;
596596
return 0;
597597
}
598598

599-
struct rtc_device *rtc_class_open(char *name)
599+
struct rtc_device *rtc_class_open(const char *name)
600600
{
601601
struct device *dev;
602602
struct rtc_device *rtc = NULL;

drivers/scsi/hosts.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,10 +468,10 @@ void scsi_unregister(struct Scsi_Host *shost)
468468
}
469469
EXPORT_SYMBOL(scsi_unregister);
470470

471-
static int __scsi_host_match(struct device *dev, void *data)
471+
static int __scsi_host_match(struct device *dev, const void *data)
472472
{
473473
struct Scsi_Host *p;
474-
unsigned short *hostnum = (unsigned short *)data;
474+
const unsigned short *hostnum = data;
475475

476476
p = class_to_shost(dev);
477477
return p->host_no == *hostnum;

drivers/scsi/osd/osd_uld.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -268,26 +268,18 @@ static inline bool _the_same_or_null(const u8 *a1, unsigned a1_len,
268268
return 0 == memcmp(a1, a2, a1_len);
269269
}
270270

271-
struct find_oud_t {
272-
const struct osd_dev_info *odi;
273-
struct device *dev;
274-
struct osd_uld_device *oud;
275-
} ;
276-
277-
int _mach_odi(struct device *dev, void *find_data)
271+
static int _match_odi(struct device *dev, const void *find_data)
278272
{
279273
struct osd_uld_device *oud = container_of(dev, struct osd_uld_device,
280274
class_dev);
281-
struct find_oud_t *fot = find_data;
282-
const struct osd_dev_info *odi = fot->odi;
275+
const struct osd_dev_info *odi = find_data;
283276

284277
if (_the_same_or_null(oud->odi.systemid, oud->odi.systemid_len,
285278
odi->systemid, odi->systemid_len) &&
286279
_the_same_or_null(oud->odi.osdname, oud->odi.osdname_len,
287280
odi->osdname, odi->osdname_len)) {
288281
OSD_DEBUG("found device sysid_len=%d osdname=%d\n",
289282
odi->systemid_len, odi->osdname_len);
290-
fot->oud = oud;
291283
return 1;
292284
} else {
293285
return 0;
@@ -301,19 +293,19 @@ int _mach_odi(struct device *dev, void *find_data)
301293
*/
302294
struct osd_dev *osduld_info_lookup(const struct osd_dev_info *odi)
303295
{
304-
struct find_oud_t find = {.odi = odi};
305-
306-
find.dev = class_find_device(&osd_uld_class, NULL, &find, _mach_odi);
307-
if (likely(find.dev)) {
296+
struct device *dev = class_find_device(&osd_uld_class, NULL, odi, _match_odi);
297+
if (likely(dev)) {
308298
struct osd_dev_handle *odh = kzalloc(sizeof(*odh), GFP_KERNEL);
299+
struct osd_uld_device *oud = container_of(dev,
300+
struct osd_uld_device, class_dev);
309301

310302
if (unlikely(!odh)) {
311-
put_device(find.dev);
303+
put_device(dev);
312304
return ERR_PTR(-ENOMEM);
313305
}
314306

315-
odh->od = find.oud->od;
316-
odh->oud = find.oud;
307+
odh->od = oud->od;
308+
odh->oud = oud;
317309

318310
return &odh->od;
319311
}

drivers/scsi/scsi_transport_iscsi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ static struct attribute_group iscsi_endpoint_group = {
183183

184184
#define ISCSI_MAX_EPID -1
185185

186-
static int iscsi_match_epid(struct device *dev, void *data)
186+
static int iscsi_match_epid(struct device *dev, const void *data)
187187
{
188188
struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
189-
uint64_t *epid = (uint64_t *) data;
189+
const uint64_t *epid = data;
190190

191191
return *epid == ep->id;
192192
}

0 commit comments

Comments
 (0)