* [Question: Drivers/base/core.c] Why dev->init_name = NULL in device_add function ?
@ 2014-08-01 17:25 Aniroop Mathur
2014-08-01 19:23 ` Greg KH
0 siblings, 1 reply; 10+ messages in thread
From: Aniroop Mathur @ 2014-08-01 17:25 UTC (permalink / raw)
To: linux-kernel, linux-hotplug, gregkh
Dear Mr. Greg Kroah-Hartman and Linux Community,
Greetings of the day !! :)
I am Aniroop Mathur working on Linux Kernel for last two years.
I am stuck at one point and could not find the solution over internet.
I posted on linuxquestions.org too.
So I need your help and suggestion for it.
Can you please help in answering my query as below:
==========================In function device_add of /drivers/base/core.c file, it is mentioned:
/*
* for statically allocated devices, which should all be converted
* some day, we need to initialize the name. We prevent reading back
* the name, and force the use of dev_name()
*/
if (dev->init_name) {
dev_set_name(dev, "%s", dev->init_name);
dev->init_name = NULL;
}
Except forcing the use of dev_name to read device name,
Is there any other reason to make init_name as NULL ?
And if it is not made NULL, is there any problem or side-effect ?
===========================
Link at linuxquestions.org:
http://www.linuxquestions.org/questions/linux-kernel-70/why-dev-init_name-%3D-null-in-device_add-function-4175504749/
Thanks a lot in advance !
Best Regards,
Aniroop Mathur
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [Question: Drivers/base/core.c] Why dev->init_name = NULL in device_add function ? 2014-08-01 17:25 [Question: Drivers/base/core.c] Why dev->init_name = NULL in device_add function ? Aniroop Mathur @ 2014-08-01 19:23 ` Greg KH 2014-08-01 22:36 ` Aniroop Mathur 0 siblings, 1 reply; 10+ messages in thread From: Greg KH @ 2014-08-01 19:23 UTC (permalink / raw) To: Aniroop Mathur; +Cc: linux-kernel, linux-hotplug On Fri, Aug 01, 2014 at 10:43:23PM +0530, Aniroop Mathur wrote: > Dear Mr. Greg Kroah-Hartman and Linux Community, > Greetings of the day !! :) > > I am Aniroop Mathur working on Linux Kernel for last two years. > I am stuck at one point and could not find the solution over internet. > I posted on linuxquestions.org too. > So I need your help and suggestion for it. > > Can you please help in answering my query as below: > > ==========================> In function device_add of /drivers/base/core.c file, it is mentioned: > /* > * for statically allocated devices, which should all be converted > * some day, we need to initialize the name. We prevent reading back > * the name, and force the use of dev_name() > */ > if (dev->init_name) { > dev_set_name(dev, "%s", dev->init_name); > dev->init_name = NULL; > } > > > Except forcing the use of dev_name to read device name, > Is there any other reason to make init_name as NULL ? Why would you want init_name to not be NULL? > And if it is not made NULL, is there any problem or side-effect ? Yes, people would start to use it thinking it was the real name of the device, when it might not be. greg k-h ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Question: Drivers/base/core.c] Why dev->init_name = NULL in device_add function ? 2014-08-01 19:23 ` Greg KH @ 2014-08-01 22:36 ` Aniroop Mathur 2014-08-01 22:41 ` Greg KH 0 siblings, 1 reply; 10+ messages in thread From: Aniroop Mathur @ 2014-08-01 22:36 UTC (permalink / raw) To: Greg KH; +Cc: linux-kernel, linux-hotplug On Sat, Aug 2, 2014 at 12:53 AM, Greg KH <gregkh@linuxfoundation.org> wrote: > On Fri, Aug 01, 2014 at 10:43:23PM +0530, Aniroop Mathur wrote: >> Dear Mr. Greg Kroah-Hartman and Linux Community, >> Greetings of the day !! :) >> >> I am Aniroop Mathur working on Linux Kernel for last two years. >> I am stuck at one point and could not find the solution over internet. >> I posted on linuxquestions.org too. >> So I need your help and suggestion for it. >> >> Can you please help in answering my query as below: >> >> ==========================>> In function device_add of /drivers/base/core.c file, it is mentioned: >> /* >> * for statically allocated devices, which should all be converted >> * some day, we need to initialize the name. We prevent reading back >> * the name, and force the use of dev_name() >> */ >> if (dev->init_name) { >> dev_set_name(dev, "%s", dev->init_name); >> dev->init_name = NULL; >> } >> >> >> Except forcing the use of dev_name to read device name, >> Is there any other reason to make init_name as NULL ? > > Why would you want init_name to not be NULL? > Currently in kernel, we cannot set name of event node. If dev->init_name is not set as NULL in device_add(), then I can easily set name of event node in evdev_dev.c file as below: if(dev->init_name) { sprintf(dev->init_name, "event_%s", dev->init_name); } error = device_add(&evdev->dev); And in some input device driver code, I will use like below: dev->init_name = "accelerometer"; input_register_device(dev); So, overall output will be /dev/input/event<x> --> /dev/input/event_accelerometer sys/class/input/input<x> --> sys/class/input/accelerometer In short, input and event node names are set just by adding one line, which i found quite efficient. There is other way also to set name of event node but it involves using extra variable and little more code, So I am looking for best solution possible. :) >> And if it is not made NULL, is there any problem or side-effect ? > > Yes, people would start to use it thinking it was the real name of the > device, when it might not be. > As the name itself nicely suggests, it is just a initial name. It may not be the final name as developer can change the name using dev_set_name. Also dev_name api is available to get final/current name of the device. Thanks and Regards, Aniroop Mathur ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Question: Drivers/base/core.c] Why dev->init_name = NULL in device_add function ? 2014-08-01 22:36 ` Aniroop Mathur @ 2014-08-01 22:41 ` Greg KH 2014-08-01 23:56 ` Aniroop Mathur 0 siblings, 1 reply; 10+ messages in thread From: Greg KH @ 2014-08-01 22:41 UTC (permalink / raw) To: Aniroop Mathur; +Cc: linux-kernel, linux-hotplug On Sat, Aug 02, 2014 at 03:54:32AM +0530, Aniroop Mathur wrote: > On Sat, Aug 2, 2014 at 12:53 AM, Greg KH <gregkh@linuxfoundation.org> wrote: > > On Fri, Aug 01, 2014 at 10:43:23PM +0530, Aniroop Mathur wrote: > >> Dear Mr. Greg Kroah-Hartman and Linux Community, > >> Greetings of the day !! :) > >> > >> I am Aniroop Mathur working on Linux Kernel for last two years. > >> I am stuck at one point and could not find the solution over internet. > >> I posted on linuxquestions.org too. > >> So I need your help and suggestion for it. > >> > >> Can you please help in answering my query as below: > >> > >> ==========================> >> In function device_add of /drivers/base/core.c file, it is mentioned: > >> /* > >> * for statically allocated devices, which should all be converted > >> * some day, we need to initialize the name. We prevent reading back > >> * the name, and force the use of dev_name() > >> */ > >> if (dev->init_name) { > >> dev_set_name(dev, "%s", dev->init_name); > >> dev->init_name = NULL; > >> } > >> > >> > >> Except forcing the use of dev_name to read device name, > >> Is there any other reason to make init_name as NULL ? > > > > Why would you want init_name to not be NULL? > > > > Currently in kernel, we cannot set name of event node. What do you mean by "event node"? > If dev->init_name is not set as NULL in device_add(), > then I can easily set name of event node in evdev_dev.c > file as below: > > if(dev->init_name) { > sprintf(dev->init_name, "event_%s", dev->init_name); > } > error = device_add(&evdev->dev); > > And in some input device driver code, I will use like below: > dev->init_name = "accelerometer"; > input_register_device(dev); What's wrong with: dev_set_name(dev, "%s", "accelerometer"); input_register_device(dev); > So, overall output will be > /dev/input/event<x> --> /dev/input/event_accelerometer > sys/class/input/input<x> --> sys/class/input/accelerometer > > In short, input and event node names are set just by > adding one line, which i found quite efficient. > There is other way also to set name of event node but > it involves using extra variable and little more code, > So I am looking for best solution possible. :) Only use init_name for static struct devices, for a dynamic one, jsut set the name like everyone else does, how is that "more" code than anything else? > >> And if it is not made NULL, is there any problem or side-effect ? > > > > Yes, people would start to use it thinking it was the real name of the > > device, when it might not be. > > > > As the name itself nicely suggests, it is just a initial name. So please do not use it, someday it will go away... thanks, greg k-h ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Question: Drivers/base/core.c] Why dev->init_name = NULL in device_add function ? 2014-08-01 22:41 ` Greg KH @ 2014-08-01 23:56 ` Aniroop Mathur 2014-08-02 2:39 ` Greg KH 2014-08-03 16:25 ` Aniroop Mathur 0 siblings, 2 replies; 10+ messages in thread From: Aniroop Mathur @ 2014-08-01 23:56 UTC (permalink / raw) To: Greg KH; +Cc: linux-kernel, linux-hotplug On Sat, Aug 2, 2014 at 4:11 AM, Greg KH <gregkh@linuxfoundation.org> wrote: > On Sat, Aug 02, 2014 at 03:54:32AM +0530, Aniroop Mathur wrote: >> On Sat, Aug 2, 2014 at 12:53 AM, Greg KH <gregkh@linuxfoundation.org> wrote: >> > On Fri, Aug 01, 2014 at 10:43:23PM +0530, Aniroop Mathur wrote: >> >> Dear Mr. Greg Kroah-Hartman and Linux Community, >> >> Greetings of the day !! :) >> >> >> >> I am Aniroop Mathur working on Linux Kernel for last two years. >> >> I am stuck at one point and could not find the solution over internet. >> >> I posted on linuxquestions.org too. >> >> So I need your help and suggestion for it. >> >> >> >> Can you please help in answering my query as below: >> >> >> >> ==========================>> >> In function device_add of /drivers/base/core.c file, it is mentioned: >> >> /* >> >> * for statically allocated devices, which should all be converted >> >> * some day, we need to initialize the name. We prevent reading back >> >> * the name, and force the use of dev_name() >> >> */ >> >> if (dev->init_name) { >> >> dev_set_name(dev, "%s", dev->init_name); >> >> dev->init_name = NULL; >> >> } >> >> >> >> >> >> Except forcing the use of dev_name to read device name, >> >> Is there any other reason to make init_name as NULL ? >> > >> > Why would you want init_name to not be NULL? >> > >> >> Currently in kernel, we cannot set name of event node. > > What do you mean by "event node"? > I am referring to the device node which HAL/Application uses as an interface to interact with kernel for read/write data operation. like /dev/input/event0, /dev/input/event1, etc int fd = open("/dev/input/event0", O_RDONLY); int res = read(fd, &input_event, sizeof(input_event)); >> If dev->init_name is not set as NULL in device_add(), >> then I can easily set name of event node in evdev_dev.c >> file as below: >> >> if(dev->init_name) { >> sprintf(dev->init_name, "event_%s", dev->init_name); >> } >> error = device_add(&evdev->dev); >> >> And in some input device driver code, I will use like below: >> dev->init_name = "accelerometer"; >> input_register_device(dev); > > What's wrong with: > dev_set_name(dev, "%s", "accelerometer"); > input_register_device(dev); > It is good way for setting name of "Input node". But it will not set name of "Event node". input_register_device call sets name of two nodes 1. Input node - sys/class/input/input<x> 2. Event node - /dev/input/event<x> or sys/class/input/event<x> Here, input<x> and event<x> are default names set without using dev_set_name in driver. input<x> - kobject name of struct input_dev; event<x> - kobject name of struct evdev; In input_register_device(dev) function call, dev refers to struct input_dev and not struct evdev. struct input_dev is defined in input.h and struct evdev is defined in evdev.c (not a header file). So driver can use struct input_dev and set its name using dev_set_name(dev, "%s", "accelerometer"); But struct evdev is not accessible to driver as it is defined in evdev.c file. So driver cannot use dev_set_name for evdev. It can only be used in evdev.c file. So above method output will be sys/class/input/accelerometer /dev/input/event<x> and sys/class/input/event<x> (event node name not set) >> So, overall output will be >> /dev/input/event<x> --> /dev/input/event_accelerometer >> sys/class/input/input<x> --> sys/class/input/accelerometer >> >> In short, input and event node names are set just by >> adding one line, which i found quite efficient. >> There is other way also to set name of event node but >> it involves using extra variable and little more code, >> So I am looking for best solution possible. :) > > Only use init_name for static struct devices, for a dynamic one, jsut > set the name like everyone else does, how is that "more" code than > anything else? > Can you please elaborate what do you mean by static struct devices ? Can I consider embedded accelerometer, proximity, gyro sensor, touch panel in android mobile devices as static devices ? Input subsystem is setting default name of input and event node. This is the normal method everyone uses. I do not want to use default name like event0, event4, input2, etc My aim is to set name of input and event node through driver as desired. So after discussion of other ways to set name through driver, we can compare which way is better. In one other method, there is a need to add extra variable in struct input_dev and hence more memory size. >> >> And if it is not made NULL, is there any problem or side-effect ? >> > >> > Yes, people would start to use it thinking it was the real name of the >> > device, when it might not be. >> > >> >> As the name itself nicely suggests, it is just a initial name. > > So please do not use it, someday it will go away... > > thanks, > Thanks and Regards, Aniroop Mathur ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Question: Drivers/base/core.c] Why dev->init_name = NULL in device_add function ? 2014-08-01 23:56 ` Aniroop Mathur @ 2014-08-02 2:39 ` Greg KH 2014-08-03 18:54 ` Aniroop Mathur 2014-08-03 16:25 ` Aniroop Mathur 1 sibling, 1 reply; 10+ messages in thread From: Greg KH @ 2014-08-02 2:39 UTC (permalink / raw) To: Aniroop Mathur; +Cc: linux-kernel, linux-hotplug On Sat, Aug 02, 2014 at 05:14:44AM +0530, Aniroop Mathur wrote: > >> So, overall output will be > >> /dev/input/event<x> --> /dev/input/event_accelerometer > >> sys/class/input/input<x> --> sys/class/input/accelerometer > >> > >> In short, input and event node names are set just by > >> adding one line, which i found quite efficient. > >> There is other way also to set name of event node but > >> it involves using extra variable and little more code, > >> So I am looking for best solution possible. :) > > > > Only use init_name for static struct devices, for a dynamic one, jsut > > set the name like everyone else does, how is that "more" code than > > anything else? > > > > Can you please elaborate what do you mean by static struct devices ? Exactly what you wrote there, 'static' is a C thing, right? > Can I consider embedded accelerometer, proximity, gyro sensor, > touch panel in android mobile devices as static devices ? Nope, because in my Android phone, I can yank out those and add new ones on the fly while the phone is running. The kernel is fully dynamic that way. > Input subsystem is setting default name of input and event node. As it should. > This is the normal method everyone uses. And so should you :) > I do not want to use default name like event0, event4, input2, etc Yes, you really do. > My aim is to set name of input and event node through driver as desired. Nope, that's userspace's job, just use udev to rename the device node, or even better yet, create a symlink like /dev/input/by-id/ has if you really need more than that. Don't mess with kernel device names, we can't do that without breaking tons of things, there's a reason that we standardized on something, please use it. good luck, greg k-h ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Question: Drivers/base/core.c] Why dev->init_name = NULL in device_add function ? 2014-08-02 2:39 ` Greg KH @ 2014-08-03 18:54 ` Aniroop Mathur 2014-08-04 4:35 ` Greg KH 0 siblings, 1 reply; 10+ messages in thread From: Aniroop Mathur @ 2014-08-03 18:54 UTC (permalink / raw) To: Greg KH; +Cc: linux-kernel, linux-hotplug On Sat, Aug 2, 2014 at 8:09 AM, Greg KH <gregkh@linuxfoundation.org> wrote: > On Sat, Aug 02, 2014 at 05:14:44AM +0530, Aniroop Mathur wrote: >> >> So, overall output will be >> >> /dev/input/event<x> --> /dev/input/event_accelerometer >> >> sys/class/input/input<x> --> sys/class/input/accelerometer >> >> >> >> In short, input and event node names are set just by >> >> adding one line, which i found quite efficient. >> >> There is other way also to set name of event node but >> >> it involves using extra variable and little more code, >> >> So I am looking for best solution possible. :) >> > >> > Only use init_name for static struct devices, for a dynamic one, jsut >> > set the name like everyone else does, how is that "more" code than >> > anything else? >> > >> >> Can you please elaborate what do you mean by static struct devices ? > > Exactly what you wrote there, 'static' is a C thing, right? > >> Can I consider embedded accelerometer, proximity, gyro sensor, >> touch panel in android mobile devices as static devices ? > > Nope, because in my Android phone, I can yank out those and add new ones > on the fly while the phone is running. The kernel is fully dynamic that > way. > >> Input subsystem is setting default name of input and event node. > > As it should. > >> This is the normal method everyone uses. > > And so should you :) > >> I do not want to use default name like event0, event4, input2, etc > > Yes, you really do. > >> My aim is to set name of input and event node through driver as desired. > > Nope, that's userspace's job, just use udev to rename the device node, > or even better yet, create a symlink like /dev/input/by-id/ has if you > really need more than that. > > Don't mess with kernel device names, we can't do that without breaking > tons of things, there's a reason that we standardized on something, > please use it. > Okay, will follow the same. :) One last thing, Why init_name will go away some day ? Is it because now we have dev_set_name, so there is no need of it anymore. Moreover as you said, "people would start to use it thinking it was the real name of the device, when it might not be." So, there remains no purpose of init_name anymore, right ? > good luck, > > greg k-h Thanks, Aniroop ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Question: Drivers/base/core.c] Why dev->init_name = NULL in device_add function ? 2014-08-03 18:54 ` Aniroop Mathur @ 2014-08-04 4:35 ` Greg KH 2014-08-04 17:11 ` Aniroop Mathur 0 siblings, 1 reply; 10+ messages in thread From: Greg KH @ 2014-08-04 4:35 UTC (permalink / raw) To: Aniroop Mathur; +Cc: linux-kernel, linux-hotplug On Mon, Aug 04, 2014 at 12:24:06AM +0530, Aniroop Mathur wrote: > On Sat, Aug 2, 2014 at 8:09 AM, Greg KH <gregkh@linuxfoundation.org> wrote: > > On Sat, Aug 02, 2014 at 05:14:44AM +0530, Aniroop Mathur wrote: > >> >> So, overall output will be > >> >> /dev/input/event<x> --> /dev/input/event_accelerometer > >> >> sys/class/input/input<x> --> sys/class/input/accelerometer > >> >> > >> >> In short, input and event node names are set just by > >> >> adding one line, which i found quite efficient. > >> >> There is other way also to set name of event node but > >> >> it involves using extra variable and little more code, > >> >> So I am looking for best solution possible. :) > >> > > >> > Only use init_name for static struct devices, for a dynamic one, jsut > >> > set the name like everyone else does, how is that "more" code than > >> > anything else? > >> > > >> > >> Can you please elaborate what do you mean by static struct devices ? > > > > Exactly what you wrote there, 'static' is a C thing, right? > > > >> Can I consider embedded accelerometer, proximity, gyro sensor, > >> touch panel in android mobile devices as static devices ? > > > > Nope, because in my Android phone, I can yank out those and add new ones > > on the fly while the phone is running. The kernel is fully dynamic that > > way. > > > >> Input subsystem is setting default name of input and event node. > > > > As it should. > > > >> This is the normal method everyone uses. > > > > And so should you :) > > > >> I do not want to use default name like event0, event4, input2, etc > > > > Yes, you really do. > > > >> My aim is to set name of input and event node through driver as desired. > > > > Nope, that's userspace's job, just use udev to rename the device node, > > or even better yet, create a symlink like /dev/input/by-id/ has if you > > really need more than that. > > > > Don't mess with kernel device names, we can't do that without breaking > > tons of things, there's a reason that we standardized on something, > > please use it. > > > > Okay, will follow the same. :) > > One last thing, > Why init_name will go away some day ? Because you should never have a static struct device in the kernel. It's a reference counted object that needs to always be dynamically allocated in order to properly work. Unfortunatly, there are some users who have it allocated statically (on the stack) instead of dynamically (on the heap). I'll get rid of them someday, it's _way_ down my list of things to do... thanks, greg k-h ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Question: Drivers/base/core.c] Why dev->init_name = NULL in device_add function ? 2014-08-04 4:35 ` Greg KH @ 2014-08-04 17:11 ` Aniroop Mathur 0 siblings, 0 replies; 10+ messages in thread From: Aniroop Mathur @ 2014-08-04 17:11 UTC (permalink / raw) To: Greg KH; +Cc: linux-kernel, linux-hotplug On Mon, Aug 4, 2014 at 10:05 AM, Greg KH <gregkh@linuxfoundation.org> wrote: > On Mon, Aug 04, 2014 at 12:24:06AM +0530, Aniroop Mathur wrote: >> On Sat, Aug 2, 2014 at 8:09 AM, Greg KH <gregkh@linuxfoundation.org> wrote: >> > On Sat, Aug 02, 2014 at 05:14:44AM +0530, Aniroop Mathur wrote: >> >> >> So, overall output will be >> >> >> /dev/input/event<x> --> /dev/input/event_accelerometer >> >> >> sys/class/input/input<x> --> sys/class/input/accelerometer >> >> >> >> >> >> In short, input and event node names are set just by >> >> >> adding one line, which i found quite efficient. >> >> >> There is other way also to set name of event node but >> >> >> it involves using extra variable and little more code, >> >> >> So I am looking for best solution possible. :) >> >> > >> >> > Only use init_name for static struct devices, for a dynamic one, jsut >> >> > set the name like everyone else does, how is that "more" code than >> >> > anything else? >> >> > >> >> >> >> Can you please elaborate what do you mean by static struct devices ? >> > >> > Exactly what you wrote there, 'static' is a C thing, right? >> > >> >> Can I consider embedded accelerometer, proximity, gyro sensor, >> >> touch panel in android mobile devices as static devices ? >> > >> > Nope, because in my Android phone, I can yank out those and add new ones >> > on the fly while the phone is running. The kernel is fully dynamic that >> > way. >> > >> >> Input subsystem is setting default name of input and event node. >> > >> > As it should. >> > >> >> This is the normal method everyone uses. >> > >> > And so should you :) >> > >> >> I do not want to use default name like event0, event4, input2, etc >> > >> > Yes, you really do. >> > >> >> My aim is to set name of input and event node through driver as desired. >> > >> > Nope, that's userspace's job, just use udev to rename the device node, >> > or even better yet, create a symlink like /dev/input/by-id/ has if you >> > really need more than that. >> > >> > Don't mess with kernel device names, we can't do that without breaking >> > tons of things, there's a reason that we standardized on something, >> > please use it. >> > >> >> Okay, will follow the same. :) >> >> One last thing, >> Why init_name will go away some day ? > > Because you should never have a static struct device in the kernel. > It's a reference counted object that needs to always be dynamically > allocated in order to properly work. Unfortunatly, there are some users > who have it allocated statically (on the stack) instead of dynamically > (on the heap). I'll get rid of them someday, it's _way_ down my list of > things to do... > > thanks, > > greg k-h Thank you so much for your support and answering my queries. :) Now, the thread has also been marked as solved. Thanks, Aniroop ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Question: Drivers/base/core.c] Why dev->init_name = NULL in device_add function ? 2014-08-01 23:56 ` Aniroop Mathur 2014-08-02 2:39 ` Greg KH @ 2014-08-03 16:25 ` Aniroop Mathur 1 sibling, 0 replies; 10+ messages in thread From: Aniroop Mathur @ 2014-08-03 16:25 UTC (permalink / raw) To: Greg KH; +Cc: linux-kernel, linux-hotplug Dear Mr. Greg KH and Linux Kernel Community, Greetings of the day ! :) I need to mark one open linux thread as solved as it is open for a long time now. Kindly help in answering my below two queries. :) On Sat, Aug 2, 2014 at 5:14 AM, Aniroop Mathur <aniroop.mathur@gmail.com> wrote: > On Sat, Aug 2, 2014 at 4:11 AM, Greg KH <gregkh@linuxfoundation.org> wrote: >> On Sat, Aug 02, 2014 at 03:54:32AM +0530, Aniroop Mathur wrote: >>> On Sat, Aug 2, 2014 at 12:53 AM, Greg KH <gregkh@linuxfoundation.org> wrote: >>> > On Fri, Aug 01, 2014 at 10:43:23PM +0530, Aniroop Mathur wrote: >>> >> Dear Mr. Greg Kroah-Hartman and Linux Community, >>> >> Greetings of the day !! :) >>> >> >>> >> I am Aniroop Mathur working on Linux Kernel for last two years. >>> >> I am stuck at one point and could not find the solution over internet. >>> >> I posted on linuxquestions.org too. >>> >> So I need your help and suggestion for it. >>> >> >>> >> Can you please help in answering my query as below: >>> >> >>> >> ==========================>>> >> In function device_add of /drivers/base/core.c file, it is mentioned: >>> >> /* >>> >> * for statically allocated devices, which should all be converted >>> >> * some day, we need to initialize the name. We prevent reading back >>> >> * the name, and force the use of dev_name() >>> >> */ >>> >> if (dev->init_name) { >>> >> dev_set_name(dev, "%s", dev->init_name); >>> >> dev->init_name = NULL; >>> >> } >>> >> >>> >> >>> >> Except forcing the use of dev_name to read device name, >>> >> Is there any other reason to make init_name as NULL ? >>> > >>> > Why would you want init_name to not be NULL? >>> > >>> >>> Currently in kernel, we cannot set name of event node. >> >> What do you mean by "event node"? >> > > I am referring to the device node which HAL/Application uses > as an interface to interact with kernel for read/write data operation. > like /dev/input/event0, /dev/input/event1, etc > > int fd = open("/dev/input/event0", O_RDONLY); > int res = read(fd, &input_event, sizeof(input_event)); > >>> If dev->init_name is not set as NULL in device_add(), >>> then I can easily set name of event node in evdev_dev.c >>> file as below: >>> >>> if(dev->init_name) { >>> sprintf(dev->init_name, "event_%s", dev->init_name); >>> } >>> error = device_add(&evdev->dev); >>> >>> And in some input device driver code, I will use like below: >>> dev->init_name = "accelerometer"; >>> input_register_device(dev); >> >> What's wrong with: >> dev_set_name(dev, "%s", "accelerometer"); >> input_register_device(dev); >> > > It is good way for setting name of "Input node". > But it will not set name of "Event node". > > input_register_device call sets name of two nodes > 1. Input node - sys/class/input/input<x> > 2. Event node - /dev/input/event<x> or sys/class/input/event<x> > > Here, input<x> and event<x> are default names set without using > dev_set_name in driver. > input<x> - kobject name of struct input_dev; > event<x> - kobject name of struct evdev; > > In input_register_device(dev) function call, > dev refers to struct input_dev and not struct evdev. > > struct input_dev is defined in input.h and > struct evdev is defined in evdev.c (not a header file). > > So driver can use struct input_dev and set its name > using dev_set_name(dev, "%s", "accelerometer"); > But struct evdev is not accessible to driver as it is defined in > evdev.c file. So driver cannot use dev_set_name for evdev. > It can only be used in evdev.c file. > > So above method output will be > sys/class/input/accelerometer > /dev/input/event<x> and sys/class/input/event<x> > (event node name not set) > >>> So, overall output will be >>> /dev/input/event<x> --> /dev/input/event_accelerometer >>> sys/class/input/input<x> --> sys/class/input/accelerometer >>> >>> In short, input and event node names are set just by >>> adding one line, which i found quite efficient. >>> There is other way also to set name of event node but >>> it involves using extra variable and little more code, >>> So I am looking for best solution possible. :) >> >> Only use init_name for static struct devices, for a dynamic one, jsut >> set the name like everyone else does, how is that "more" code than >> anything else? >> > > Can you please elaborate what do you mean by static struct devices ? > Can I consider embedded accelerometer, proximity, gyro sensor, > touch panel in android mobile devices as static devices ? > 1. What are statically allocated devices and dynamically allocated devices ? > Input subsystem is setting default name of input and event node. > This is the normal method everyone uses. > > I do not want to use default name like event0, event4, input2, etc > My aim is to set name of input and event node through driver as desired. > So after discussion of other ways to set name through driver, > we can compare which way is better. > In one other method, there is a need to add extra variable in > struct input_dev and hence more memory size. > >>> >> And if it is not made NULL, is there any problem or side-effect ? >>> > >>> > Yes, people would start to use it thinking it was the real name of the >>> > device, when it might not be. >>> > >>> >>> As the name itself nicely suggests, it is just a initial name. >> >> So please do not use it, someday it will go away... >> 2. Why init_name field will be removed from struct device someday ? >> thanks, >> > Thanks, Aniroop ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2014-08-04 17:11 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-08-01 17:25 [Question: Drivers/base/core.c] Why dev->init_name = NULL in device_add function ? Aniroop Mathur 2014-08-01 19:23 ` Greg KH 2014-08-01 22:36 ` Aniroop Mathur 2014-08-01 22:41 ` Greg KH 2014-08-01 23:56 ` Aniroop Mathur 2014-08-02 2:39 ` Greg KH 2014-08-03 18:54 ` Aniroop Mathur 2014-08-04 4:35 ` Greg KH 2014-08-04 17:11 ` Aniroop Mathur 2014-08-03 16:25 ` Aniroop Mathur
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).