uevent: cleanup of macio and add for of_platform
Subsystems (2)
Hi everyone, Hi Ben,
Theses two patches are not heavily tested. For the macio cleanup I just don't have any hardware to run it on, and for the of_platform support I just tested it compiles and doesn't crash on boot.
So if you're in position of testing either, that would be great.
Sylvain
[RFC/T] macintosh: tidy up uevent handler by using add_uevent_var
This add_uevent_var helper is specifically there for that task and that makes the code more readable.
Signed-off-by Sylvain Munaut <[email protected]>
--- drivers/macintosh/macio_asic.c | 91 +++++++++++++++------------------------- 1 files changed, 34 insertions(+), 57 deletions(-)
drivers/macintosh/macio_asic.c +34 -57
@@ -139,11 +139,12 @@ static int macio_uevent(struct device *d {struct macio_dev * macio_dev;struct of_device * of; -char *scratch; -const char *compat, *compat2; +const char *compat; +char *compat2; +char compat_buf[128 ];/* need to be size of 'compatible' */ int i =0 ; -int length, cplen, cplen2, seen =0 ; +int length =0 , cplen, seen =0 ;if (!dev)return -ENODEV ;
@@ -155,75 +156,51 @@ static int macio_uevent(struct device *d of = &macio_dev->ofdev;/* stuff we want to pass to /sbin/hotplug */ - envp[i++] = scratch = buffer; - length =scnprintf (scratch, buffer_size,"OF_NAME=%s" , of->node->name); - ++length; - buffer_size -= length; -if ((buffer_size <=0 ) || (i >= num_envp)) +if (add_uevent_var (envp, num_envp, &i, + buffer, buffer_size, &length, +"OF_NAME=%s" , of->node->name))return -ENOMEM ; - scratch += length; - envp[i++] = scratch; - length =scnprintf (scratch, buffer_size,"OF_TYPE=%s" , of->node->type); - ++length; - buffer_size -= length; -if ((buffer_size <=0 ) || (i >= num_envp)) +if (add_uevent_var (envp, num_envp, &i, + buffer, buffer_size, &length, +"OF_TYPE=%s" , of->node->type))return -ENOMEM ; - scratch += length;/* Since the compatible field can contain pretty much anything * it's not really legal to split it out with commas. We split it * up using a number of environment variables instead. */ compat =get_property (of->node,"compatible" , &cplen); - compat2 = compat; - cplen2= cplen; + compat2 = compat_buf; +if (compat) +strcat (compat2, compat);while (compat && cplen >0 ) { - envp[i++] = scratch; - length =scnprintf (scratch, buffer_size, -"OF_COMPATIBLE_%d=%s" , seen, compat); - ++length; - buffer_size -= length; -if ((buffer_size <=0 ) || (i >= num_envp)) +int sl; +if (add_uevent_var (envp, num_envp, &i, + buffer, buffer_size, &length, +"OF_COMPATIBLE_%d=%s" , seen, compat))return -ENOMEM ; - scratch += length; - length =strlen (compat) +1 ; - compat += length; - cplen -= length; + + sl =strlen (compat) +1 ; + compat += sl; + compat2 += sl; + cplen -= sl; seen++; + compat2[-1 ] ='C' ; } + compat2[seen?-1 :0 ] =0 ; - envp[i++] = scratch; - length =scnprintf (scratch, buffer_size,"OF_COMPATIBLE_N=%d" , seen); - ++length; - buffer_size -= length; -if ((buffer_size <=0 ) || (i >= num_envp)) -return -ENOMEM ; - scratch += length; - - envp[i++] = scratch; - length =scnprintf (scratch, buffer_size,"MODALIAS=of:N%sT%s" , - of->node->name, of->node->type); -/* overwrite '\0' */ - buffer_size -= length; -if ((buffer_size <=0 ) || (i >= num_envp)) +if (add_uevent_var (envp, num_envp, &i, + buffer, buffer_size, &length, +"OF_COMPATIBLE_N=%d" , seen))return -ENOMEM ; - scratch += length; -if (!compat2) { - compat2 ="" ; - cplen2 =1 ; - } -while (cplen2 >0 ) { - length =snprintf (scratch, buffer_size,"C%s" , compat2); - buffer_size -= length; -if (buffer_size <=0 ) -return -ENOMEM ; - scratch += length; - length =strlen (compat2) +1 ; - compat2 += length; - cplen2 -= length; - } +if (add_uevent_var (envp, num_envp, &i, + buffer, buffer_size, &length, +"MODALIAS=of:N%sT%sC%s" , + of->node->name, of->node->type, + compat_buf)) +return -ENOMEM ; envp[i] =NULL ;
@@ -235,7 +212,7 @@ extern struct device_attribute macio_devstruct bus_type macio_bus_type = { .name ="macio" , .match = macio_bus_match, - .uevent = macio_uevent, + .uevent = macio_uevent, .probe = macio_device_probe, .remove = macio_device_remove, .shutdown = macio_device_shutdown,
Signature · 1 line
1.4.2
[RFC/T] powerpc: Add support for uevent to of_platform
This adds a proper uevent handler to the of_platform bus. This allows autoloading of modules (or at least should ;). It's _heavily_ based on the macio counterpart.
Signed-off-by Sylvain Munaut <[email protected]>
--- arch/powerpc/kernel/of_platform.c | 71 +++++++++++++++++++++++++++++++++++++ 1 files changed, 71 insertions(+), 0 deletions(-)
arch/powerpc/kernel/of_platform.c +71 -0
@@ -73,6 +73,76 @@ static int of_platform_bus_match(structreturn of_match_device (matches, of_dev) !=NULL ; } +static int of_platform_uevent (struct device *dev,char **envp,int num_envp, +char *buffer,int buffer_size) +{ +struct of_device *of; +const char *compat; +char *compat2; +char compat_buf[128 ];/* need to be size of 'compatible' */ + +int i =0 ; +int length =0 , cplen, seen =0 ; + +if (!dev) +return -ENODEV ; + + of =to_of_device (dev); +if (!of) +return -ENODEV ; + +/* stuff we want to pass to /sbin/hotplug */ +if (add_uevent_var (envp, num_envp, &i, + buffer, buffer_size, &length, +"OF_NAME=%s" , of->node->name)) +return -ENOMEM ; + +if (add_uevent_var (envp, num_envp, &i, + buffer, buffer_size, &length, +"OF_TYPE=%s" , of->node->type)) +return -ENOMEM ; + +/* Since the compatible field can contain pretty much anything +* it's not really legal to split it out with commas. We split it +* up using a number of environment variables instead. */ + + compat =get_property (of->node,"compatible" , &cplen); + compat2 = compat_buf; +if (compat) +strcat (compat2, compat); +while (compat && cplen >0 ) { +int sl; +if (add_uevent_var (envp, num_envp, &i, + buffer, buffer_size, &length, +"OF_COMPATIBLE_%d=%s" , seen, compat)) +return -ENOMEM ; + + sl =strlen (compat) +1 ; + compat += sl; + compat2 += sl; + cplen -= sl; + seen++; + compat2[-1 ] ='C' ; + } + compat2[seen?-1 :0 ] =0 ; + +if (add_uevent_var (envp, num_envp, &i, + buffer, buffer_size, &length, +"OF_COMPATIBLE_N=%d" , seen)) +return -ENOMEM ; + +if (add_uevent_var (envp, num_envp, &i, + buffer, buffer_size, &length, +"MODALIAS=of:N%sT%sC%s" , + of->node->name, of->node->type, + compat_buf)) +return -ENOMEM ; + + envp[i] =NULL ; + +return 0 ; +} +static int of_platform_device_probe (struct device *dev) {int error = -ENODEV ;
@@ -132,6 +202,7 @@ static int of_platform_device_resume(strstruct bus_type of_platform_bus_type = { .name ="of_platform" , .match = of_platform_bus_match, + .uevent = of_platform_uevent, .probe = of_platform_device_probe, .remove = of_platform_device_remove, .suspend = of_platform_device_suspend,
Signature · 1 line
1.4.2