PATCPATCH -- add unlimited name lengths support to sysfs
Hi All,
In the development of RPA PCI Hot Plug Controller driver, I have found it is needed to create some kernel objects which have more than 20 (KOBJECT_NAME_SIZE) charaters in their name strings. At a later time the names will be used for creating some symlinks. The attached patch adds unlimited name lengths support to sysfs symlink.c.
Comments are welcome.
Linda
fs/sysfs/symlink.c +16 -4
@@ -42,7 +42,10 @@struct kobject * p = kobj;int length =1 ;do { - length +=strlen (p->name) +1 ; +if (p->k_name) + length +=strlen (p->k_name) +1 ; +else + length +=strlen (p->name) +1 ; p = p->parent; }while (p);return length;
@@ -54,11 +57,20 @@ --length;for (p = kobj; p; p = p->parent) { -int cur =strlen (p->name); - +int cur; +char *name; + +if (p->k_name) { + cur =strlen (p->k_name); + name = p->k_name; + } +else { + cur =strlen (p->name); + name = p->name; + }/* back up enough to print this bus id with '/' */ length -= cur; -strncpy (buffer + length,p->name,cur); +strncpy (buffer + length,name,cur); *(buffer + --length) ='/' ; } }
fs/sysfs/symlink.c line 48
Quoted 12 lines · Linda Xie
diff -Nru
a/fs/sysfs/symlink.cb/fs/sysfs/symlink.cfs/sysfs/symlink.c +4
-1@@ -42,7 +42,10 @@struct kobject * p = kobj;int length =1 ; do { - length += strlen(p->name) + 1; + if (p->k_name) + length += strlen(p->k_name) + 1; + else + length += strlen(p->name) + 1;
Shouldn't this just be:
length += strlen(kobject_name(p)) + 1;
Quoted 7 lines
fs/sysfs/symlink.c +1
-2@@ -54,11 +57,20 @@ --length;for (p = kobj; p; p = p->parent) { -int cur =strlen (p->name); - +int cur;
fs/sysfs/symlink.c line 70
Quoted 10 lines
fs/sysfs/symlink.c +10
-0+char *name; + +if (p->k_name) { + cur =strlen (p->k_name); + name = p->k_name; + } +else { + cur =strlen (p->name); + name = p->name; + }
Same here, just use kobject_name() to get the proper pointer.
thanks,
greg k-h
Quoted 17 lines · Greg KH
fs/sysfs/symlink.c line 48
Quoted 12 lines · Linda Xie
diff -Nru
a/fs/sysfs/symlink.cb/fs/sysfs/symlink.cfs/sysfs/symlink.c +4
-1@@ -42,7 +42,10 @@struct kobject * p = kobj;int length =1 ; do { - length += strlen(p->name) + 1; + if (p->k_name) + length += strlen(p->k_name) + 1; + else + length += strlen(p->name) + 1;Shouldn't this just be:
Quoted 2 lines
length += strlen(kobject_name(p)) + 1;
That is correct. But here is my concern: Some of the callers of sysfs_create_link()
set p->name instead of p->k_name. So for them, the length calculated using kobject_name(p) will be incorrect. Correct me if I am wrong.
Thanks,
Linda
Quoted 22 lines
Quoted 8 lines
fs/sysfs/symlink.c +1
-2@@ -54,11 +57,20 @@ --length;for (p = kobj; p; p = p->parent) { -int cur =strlen (p->name); - +int cur;fs/sysfs/symlink.c line 70
Quoted 10 lines
fs/sysfs/symlink.c +10
-0+char *name; + +if (p->k_name) { + cur =strlen (p->k_name); + name = p->k_name; + } +else { + cur =strlen (p->name); + name = p->name; + }Same here, just use
kobject_name()to get the proper pointer.
Quoted 3 lines
thanks,
greg k-h
Thanks,
Linda
Quoted 21 lines · Linda Xie
Quoted 17 lines · Greg KH
fs/sysfs/symlink.c line 48
Quoted 12 lines · Linda Xie
diff -Nru
a/fs/sysfs/symlink.cb/fs/sysfs/symlink.cfs/sysfs/symlink.c +4
-1@@ -42,7 +42,10 @@struct kobject * p = kobj;int length =1 ; do { - length += strlen(p->name) + 1; + if (p->k_name) + length += strlen(p->k_name) + 1; + else + length += strlen(p->name) + 1;Shouldn't this just be:
Quoted 2 lines
length += strlen(kobject_name(p)) + 1;
Quoted 4 lines
That is correct. But here is my concern: Some of the callers of
sysfs_create_link()
setp->nameinstead ofp->k_name. So for them, the length calculated usingkobject_name(p)will be incorrect. Correct me if I am wrong.
Well if a kobject only uses the .name field, .k_name will point to it (see kobject_add()), so the kobject_name() call will work in the above case (as it should always do.) Actually that if (p->k_name) statement will always be true because of this fact :)
This lets people like the edd driver which does:
snprintf(edev->kobj.name, EDD_DEVICE_NAME_SIZE, "int13_dev%02x", edd[i].device);
still work properly. Ideally, callers like this should change to use the kobject_set_name() function, but there's no rush.
thanks,
greg k-h
Quoted 34 lines · Greg KH
Quoted 23 lines · Linda Xie
Quoted 18 lines · Greg KH
fs/sysfs/symlink.c line 48
Quoted 12 lines · Linda Xie
diff -Nru
a/fs/sysfs/symlink.cb/fs/sysfs/symlink.cfs/sysfs/symlink.c +4
-1@@ -42,7 +42,10 @@struct kobject * p = kobj;int length =1 ; do { - length += strlen(p->name) + 1; + if (p->k_name) + length += strlen(p->k_name) + 1; + else + length += strlen(p->name) + 1;Shouldn't this just be:
Quoted 2 lines
length += strlen(kobject_name(p)) + 1;Quoted 2 lines
That is correct. But here is my concern: Some of the callers of
sysfs_create_link()
setp->nameinstead ofp->k_name. So for them, the length calculated usingkobject_name(p)will be incorrect. Correct me if I am wrong.Well if a kobject only uses the .name field, .k_name will point to it (see
kobject_add()), so thekobject_name()call will work in the above case (as it should always do.) Actually that if (p->k_name) statement will always be true because of this fact :)
Quoted 9 lines
This lets people like the edd driver which does:
snprintf(edev->kobj.name, EDD_DEVICE_NAME_SIZE, "int13_dev%02x", edd[i].device);still work properly. Ideally, callers like this should change to use the
kobject_set_name()function, but there's no rush.thanks,
greg k-h
Thank you very much. Below is an updated patch:
fs/sysfs/symlink.c Wed Dec 17 20:08:01 2003 +3 -3
@@ -42,7 +42,7 @@ struct kobject * p = kobj; int length = 1; do { - length += strlen(p->name) + 1; + length += strlen(kobject_name(p)) + 1; p = p->parent; } while (p); return length;
@@ -54,11 +54,11 @@ --length; for (p = kobj; p; p = p->parent) { - int cur = strlen(p->name); + int cur = strlen(kobject_name(p)); /* back up enough to print this bus id with '/' */ length -= cur; - strncpy(buffer + length,p->name,cur); + strncpy(buffer + length,kobject_name(p),cur); *(buffer + --length) = '/'; }
Linda
Quoted 43 lines · Linda Xie
Quoted 42 lines · Greg KH
Quoted 23 lines · Linda Xie
Quoted 18 lines · Greg KH
fs/sysfs/symlink.c line 48
Quoted 12 lines · Linda Xie
diff -Nru
a/fs/sysfs/symlink.cb/fs/sysfs/symlink.cfs/sysfs/symlink.c +4
-1@@ -42,7 +42,10 @@struct kobject * p = kobj;int length =1 ; do { - length += strlen(p->name) + 1; + if (p->k_name) + length += strlen(p->k_name) + 1; + else + length += strlen(p->name) + 1;Shouldn't this just be:
Quoted 2 lines
length += strlen(kobject_name(p)) + 1;Quoted 4 lines
That is correct. But here is my concern: Some of the callers of
sysfs_create_link()
setp->nameinstead ofp->k_name. So for them, the length calculated usingkobject_name(p)will be incorrect. Correct me if I am wrong.Well if a kobject only uses the .name field, .k_name will point to it (see
kobject_add()), so thekobject_name()call will work in the above case (as it should always do.) Actually that if (p->k_name) statement will always be true because of this fact :)This lets people like the edd driver which does:
snprintf(edev->kobj.name, EDD_DEVICE_NAME_SIZE, "int13_dev%02x", edd[i].device);still work properly. Ideally, callers like this should change to use the
kobject_set_name()function, but there's no rush.
Quoted 6 lines
Quoted 4 lines
thanks,
greg k-h
Thank you very much. Below is an updated patch:
Ick, that patch had no tabs :(
Care to fix your email client and send it to me again?
thanks,
greg k-h