Some cleanup in driver core
cover Some cleanup in driver core
These two patches do some cleanup in the driver core.
They are tested on:
Hardware: Lenovo T420 Kernel Version: 3.8
Result:
* /sys/devices/pci0000:00/ directory is correct
* /sys/devices/pci0000:00/0000:00:19.0/ contains the sysfs files for a pci device
Wei Yang (2):
driver core: remove device_add_attrs() in drivers/base/bus.c
driver-core: remove the duplicate assignment of kobj->parent in
device_add
drivers/base/bus.c | 21 +-------------------- drivers/base/core.c | 6 ++---- include/linux/device.h | 2 ++ 3 files changed, 5 insertions(+), 24 deletions(-)
Signature · 1 line
1.7.5.4
PATCH 1/2 driver core: remove device_add_attrs() in drivers/base/bus.c
Originally, we have two functions named device_add_attrs() in drivers/base/bus.c and drivers/base/core.c. This will cause some confusion when reading the code.
And the one in drivers/base/bus.c do the same action as device_add_attributes() in drivers/base/core.c. That would be better to reuse this code.
This patch just do some cleanup. Remove the device_add_attrs() in drivers/base/bus.c and call device_add_attributes() directly.
--- drivers/base/bus.c | 21 +-------------------- drivers/base/core.c | 2 +- include/linux/device.h | 2 ++ 3 files changed, 4 insertions(+), 21 deletions(-)
drivers/base/bus.c +1 -20
@@ -452,25 +452,6 @@ int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, }EXPORT_SYMBOL_GPL (bus_for_each_drv); -static int device_add_attrs (struct bus_type *bus,struct device *dev) -{ -int error =0 ; -int i; - -if (!bus->dev_attrs) -return 0 ; - -for (i =0 ;attr_name (bus->dev_attrs[i]); i++) { - error =device_create_file (dev, &bus->dev_attrs[i]); -if (error) { -while (--i >=0 ) -device_remove_file (dev, &bus->dev_attrs[i]); -break ; - } - } -return error; -} -static void device_remove_attrs (struct bus_type *bus,struct device *dev) {int i;
@@ -496,7 +477,7 @@ int bus_add_device(struct device *dev)if (bus) {pr_debug ("bus: '%s': add device %s\n" , bus->name,dev_name (dev)); - error =device_add_attrs (bus, dev); + error =device_add_attributes (dev, bus->dev_attrs);if (error) goto out_put; error = sysfs_create_link(&bus->p->devices_kset->kobj,
drivers/base/core.c +1 -1
@@ -397,7 +397,7 @@ static ssize_t store_uevent(struct device *dev, struct device_attribute *attr,static struct device_attribute uevent_attr =__ATTR (uevent,S_IRUGO |S_IWUSR , show_uevent, store_uevent); -static int device_add_attributes (struct device *dev, +int device_add_attributes (struct device *dev,struct device_attribute *attrs) {int error =0 ;
include/linux/device.h +2 -0
@@ -518,6 +518,8 @@ ssize_t device_store_bool(struct device *dev, struct device_attribute *attr, struct device_attribute dev_attr_##_name = \ __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) +extern int device_add_attributes (struct device *dev, +struct device_attribute *attrs);extern int device_create_file (struct device *device,const struct device_attribute *entry); extern void device_remove_file(struct device *dev,
Signature · 1 line
1.7.5.4
Greg KH
maintainerRe: [PATCH 1/2] driver core: remove device_add_attrs() in drivers/base/bus.c
Quoted 3 lines · Wei Yang
Originally, we have two functions named
device_add_attrs()indrivers/base/bus.canddrivers/base/core.c. This will cause some confusion when reading the code.
Why? It's just static functions.
Quoted 2 lines
And the one in
drivers/base/bus.cdo the same action asdevice_add_attributes()indrivers/base/core.c. That would be better to reuse this code.
Possibly, yes, but you put the .h entry in the wrong place, thereby exposing a previously static function to the entire kernel, which is not good at all. Why did you do that? Are you now going to want to call that function from some driver?
greg k-h
Re: [PATCH 1/2] driver core: remove device_add_attrs() in drivers/base/bus.c
Quoted 6 lines · Greg KH
Quoted 3 lines · Wei Yang
Originally, we have two functions named
device_add_attrs()indrivers/base/bus.canddrivers/base/core.c. This will cause some confusion when reading the code.Why? It's just static functions.
Hmm, yes, they are static functions.
The confusion comes from myself. When I look for the definitions of the function in cscope, it pop out two line with the same name. So I just think whether we can help the reader, if there is only one pop up.
Well, I have to admit this is my personal feeling and due to my lack of experence.
Quoted 6 lines
Quoted 3 lines
And the one in
drivers/base/bus.cdo the same action asdevice_add_attributes()indrivers/base/core.c. That would be better to reuse this code.Possibly, yes, but you put the .h entry in the wrong place, thereby exposing a previously static function to the entire kernel, which is not
Agree, this is not a good idea to expose an extra interface to the entire kernel.
Quoted 2 lines
good at all. Why did you do that? Are you now going to want to call that function from some driver?
The reason for this patch is, the logic in these two functions are the same. My purpose is to reuse the code and save some space for the kernel image, well, I have to admit it is just a very small piece of space.
Quoted 2 lines
greg k-h
Signature · 2 lines
Richard Yang Help you, Help me
PATCH 2/2 driver-core: remove the duplicate assignment of kobj->parent in device_add
In reply to Wei Yangkobject_add() will setup the kobject parent correctly.
This patch removes the redundant code.
--- drivers/base/core.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/base/core.c +1 -3
@@ -1024,8 +1024,6 @@ int device_add(struct device *dev) parent =get_device (dev->parent); kobj =get_device_parent (dev, parent); -if (kobj) - dev->kobj.parent = kobj;/* use parent numa_node */ if (parent)
@@ -1033,7 +1031,7 @@ int device_add(struct device *dev)/* first, register with generic layer. */ /* we require the name to be set before, and pass NULL */ - error =kobject_add (&dev->kobj, dev->kobj.parent,NULL ); + error =kobject_add (&dev->kobj, kobj,NULL );if (error) goto Error;
Signature · 1 line
1.7.5.4
Re: [PATCH 2/2] driver-core: remove the duplicate assignment of kobj->parent in device_add
Quoted 25 lines · Wei Yang
kobject_add()will setup the kobject parent correctly.This patch removes the redundant code.
Signed-off-by Wei Yang <[email protected]>Reviewed-by Ram Pai <[email protected]>Reviewed-by Gavin Shan <[email protected]>--- drivers/base/core.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)drivers/base/core.c +0
-2@@ -1024,8 +1024,6 @@ int device_add(struct device *dev) parent =get_device (dev->parent); kobj =get_device_parent (dev, parent); -if (kobj) - dev->kobj.parent = kobj;/* use parent numa_node */ if (parent)
drivers/base/core.c int device_add(struct device *dev) · line 1036
Quoted 7 lines
drivers/base/core.c +1
-1@@ -1033,7 +1031,7 @@ int device_add(struct device *dev)/* first, register with generic layer. */ /* we require the name to be set before, and pass NULL */ - error =kobject_add (&dev->kobj, dev->kobj.parent,NULL ); + error =kobject_add (&dev->kobj, kobj,NULL );if (error) goto Error;
You've submitted this exact same patch before and Greg asked a couple of questions about it: https://lkml.org/lkml/2013/1/25/599
If this is a resubmission, then it would sure be nice if that was clear from the subject and on. And I believe any previously asked questions should be answered in some way. I see that you have responded to one of them by moving part of the commit message to the cover letter, but still without any answer to the question.
To me this looks like you completely ignored Greg's review questions. Is that so?
Bjørn
A message that is not in the archive (sent off-list or not yet received): 20130307135032.GA6100@richard.(null)
Re: [PATCH 2/2] driver-core: remove the duplicate assignment of kobj->parent in device_add
[ not stripping any quoting to restore context for linux-kernel]
Quoted 62 lines · Wei Yang
Quoted 39 lines · Bjørn Mork
Quoted 25 lines · Wei Yang
kobject_add()will setup the kobject parent correctly.This patch removes the redundant code.
Signed-off-by Wei Yang <[email protected]>Reviewed-by Ram Pai <[email protected]>Reviewed-by Gavin Shan <[email protected]>--- drivers/base/core.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)drivers/base/core.c +0
-2@@ -1024,8 +1024,6 @@ int device_add(struct device *dev) parent =get_device (dev->parent); kobj =get_device_parent (dev, parent); -if (kobj) - dev->kobj.parent = kobj;/* use parent numa_node */ if (parent)drivers/base/core.c int device_add(struct device *dev) · line 1036
Quoted 7 lines
drivers/base/core.c +1
-1@@ -1033,7 +1031,7 @@ int device_add(struct device *dev)/* first, register with generic layer. */ /* we require the name to be set before, and pass NULL */ - error =kobject_add (&dev->kobj, dev->kobj.parent,NULL ); + error =kobject_add (&dev->kobj, kobj,NULL );if (error) goto Error;You've submitted this exact same patch before and Greg asked a couple of questions about it: https://lkml.org/lkml/2013/1/25/599
Quoted 8 lines
If this is a resubmission, then it would sure be nice if that was clear from the subject and on. And I believe any previously asked questions should be answered in some way. I see that you have responded to one of them by moving part of the commit message to the cover letter, but still without any answer to the question.
To me this looks like you completely ignored Greg's review questions. Is that so?
Bjør,
Thanks for your response.
In my mail box, I just see one mail from Greg and replied. Below is my screen in my mutt. You see I replied and wait for the further comment for several days and send out another reply on Feb 02. Well not receive further comment.
976 Jan 23 Wei Yang ( 37) [PATCH] driver-core: remove the duplicate assignment of kobj->parent in device_add 977 r Jan 25 Greg KH ( 17) `-> 978 r Jan 28 Wei Yang ( 43) `-> 979 Feb 02 Wei Yang ( 52) `->
Quoted 6 lines
Hmm... I am confused with this, maybe my mail box get some problem. Could you see this mail? Or if someone could see this mail, would you please reply so that I will be sure that I have really sent it out .
BTW, no one see my reply? I looked in the url you mentioned, really not see my reply. I am sorry for that.
I cannot answer where your reply may have gone. I do however note that this reply to me went to every address on the CC list *except* [email protected]. Why? That would make it appear as you never answered me to 99.999997% of the linux-kernel readers...
Anyway, the main point is really not whether your mail went anywhere or not. If this was indeed an intentional resend, then I do expect it to say so and to contain information about how previous review comments were resolved. Most people would not rememeber your answer even it was sent to the mailing list.
Bjørn
Greg KH
maintainerQuoted 1 line · Wei Yang
These two patches do some cleanup in the driver core.
No they do not.
I understand the need to fix code, but please, do so if it is broken. These patches don't help, and in fact, they hurt things.
Next time, if you wish to send me patches like this, please get someone else at IBM, who is experienced, to ack them, before sending them on to me.
greg k-h
Quoted 7 lines · Greg KH
Quoted 1 line · Wei Yang
These two patches do some cleanup in the driver core.
No they do not.
I understand the need to fix code, but please, do so if it is broken. These patches don't help, and in fact, they hurt things.
Sorry for my bad patch.
Quoted 4 lines
Next time, if you wish to send me patches like this, please get someone else at IBM, who is experienced, to ack them, before sending them on to me.
Sorry for doing that, I will contact the experienced first next time.
Quoted 2 lines
greg k-h
Signature · 2 lines
Richard Yang Help you, Help me