Skip to content

Commit 1fa5ae8

Browse files
kaysieversgregkh
authored andcommitted
driver core: get rid of struct device's bus_id string array
Now that all users of bus_id is gone, we can remove it from struct device. Signed-off-by: Kay Sievers <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6866ac9 commit 1fa5ae8

File tree

4 files changed

+23
-24
lines changed

4 files changed

+23
-24
lines changed

drivers/base/core.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -777,17 +777,12 @@ static void device_remove_class_symlinks(struct device *dev)
777777
int dev_set_name(struct device *dev, const char *fmt, ...)
778778
{
779779
va_list vargs;
780-
char *s;
780+
int err;
781781

782782
va_start(vargs, fmt);
783-
vsnprintf(dev->bus_id, sizeof(dev->bus_id), fmt, vargs);
783+
err = kobject_set_name_vargs(&dev->kobj, fmt, vargs);
784784
va_end(vargs);
785-
786-
/* ewww... some of these buggers have / in the name... */
787-
while ((s = strchr(dev->bus_id, '/')))
788-
*s = '!';
789-
790-
return 0;
785+
return err;
791786
}
792787
EXPORT_SYMBOL_GPL(dev_set_name);
793788

@@ -864,12 +859,17 @@ int device_add(struct device *dev)
864859
if (!dev)
865860
goto done;
866861

867-
/* Temporarily support init_name if it is set.
868-
* It will override bus_id for now */
869-
if (dev->init_name)
870-
dev_set_name(dev, "%s", dev->init_name);
862+
/*
863+
* for statically allocated devices, which should all be converted
864+
* some day, we need to initialize the name. We prevent reading back
865+
* the name, and force the use of dev_name()
866+
*/
867+
if (dev->init_name) {
868+
dev_set_name(dev, dev->init_name);
869+
dev->init_name = NULL;
870+
}
871871

872-
if (!strlen(dev->bus_id))
872+
if (!dev_name(dev))
873873
goto done;
874874

875875
pr_debug("device: '%s': %s\n", dev_name(dev), __func__);
@@ -1348,7 +1348,10 @@ struct device *device_create_vargs(struct class *class, struct device *parent,
13481348
dev->release = device_create_release;
13491349
dev_set_drvdata(dev, drvdata);
13501350

1351-
vsnprintf(dev->bus_id, BUS_ID_SIZE, fmt, args);
1351+
retval = kobject_set_name_vargs(&dev->kobj, fmt, args);
1352+
if (retval)
1353+
goto error;
1354+
13521355
retval = device_register(dev);
13531356
if (retval)
13541357
goto error;
@@ -1452,19 +1455,15 @@ int device_rename(struct device *dev, char *new_name)
14521455
old_class_name = make_class_name(dev->class->name, &dev->kobj);
14531456
#endif
14541457

1455-
old_device_name = kmalloc(BUS_ID_SIZE, GFP_KERNEL);
1458+
old_device_name = kstrdup(dev_name(dev), GFP_KERNEL);
14561459
if (!old_device_name) {
14571460
error = -ENOMEM;
14581461
goto out;
14591462
}
1460-
strlcpy(old_device_name, dev->bus_id, BUS_ID_SIZE);
1461-
strlcpy(dev->bus_id, new_name, BUS_ID_SIZE);
14621463

14631464
error = kobject_rename(&dev->kobj, new_name);
1464-
if (error) {
1465-
strlcpy(dev->bus_id, old_device_name, BUS_ID_SIZE);
1465+
if (error)
14661466
goto out;
1467-
}
14681467

14691468
#ifdef CONFIG_SYSFS_DEPRECATED
14701469
if (old_class_name) {

include/linux/device.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,6 @@ struct device {
374374
struct device *parent;
375375

376376
struct kobject kobj;
377-
char bus_id[BUS_ID_SIZE]; /* position on parent bus */
378377
unsigned uevent_suppress:1;
379378
const char *init_name; /* initial name of the device */
380379
struct device_type *type;
@@ -427,8 +426,7 @@ struct device {
427426

428427
static inline const char *dev_name(const struct device *dev)
429428
{
430-
/* will be changed into kobject_name(&dev->kobj) in the near future */
431-
return dev->bus_id;
429+
return kobject_name(&dev->kobj);
432430
}
433431

434432
extern int dev_set_name(struct device *dev, const char *name, ...)

include/linux/kobject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ struct kobject {
7272

7373
extern int kobject_set_name(struct kobject *kobj, const char *name, ...)
7474
__attribute__((format(printf, 2, 3)));
75+
extern int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
76+
va_list vargs);
7577

7678
static inline const char *kobject_name(const struct kobject *kobj)
7779
{

lib/kobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static int kobject_add_internal(struct kobject *kobj)
212212
* @fmt: format string used to build the name
213213
* @vargs: vargs to format the string.
214214
*/
215-
static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
215+
int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
216216
va_list vargs)
217217
{
218218
const char *old_name = kobj->name;

0 commit comments

Comments
 (0)