aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/power_supply_sysfs.c
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2007-08-14 09:15:12 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-10-12 17:51:01 -0400
commit7eff2e7a8b65c25920207324e56611150eb1cd9a (patch)
tree02a0eeba9d25d996233e30c18f258dfae0ae2139 /drivers/power/power_supply_sysfs.c
parent8380770c842faef3001e44662953d64ad9a93663 (diff)
Driver core: change add_uevent_var to use a struct
This changes the uevent buffer functions to use a struct instead of a long list of parameters. It does no longer require the caller to do the proper buffer termination and size accounting, which is currently wrong in some places. It fixes a known bug where parts of the uevent environment are overwritten because of wrong index calculations. Many thanks to Mathieu Desnoyers for finding bugs and improving the error handling. Signed-off-by: Kay Sievers <kay.sievers@vrfy.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> Cc: Cornelia Huck <cornelia.huck@de.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/power/power_supply_sysfs.c')
-rw-r--r--drivers/power/power_supply_sysfs.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
index de3155b21285..249f61bae639 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -195,11 +195,10 @@ static char *kstruprdup(const char *str, gfp_t gfp)
195 return ret; 195 return ret;
196} 196}
197 197
198int power_supply_uevent(struct device *dev, char **envp, int num_envp, 198int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env)
199 char *buffer, int buffer_size)
200{ 199{
201 struct power_supply *psy = dev_get_drvdata(dev); 200 struct power_supply *psy = dev_get_drvdata(dev);
202 int i = 0, length = 0, ret = 0, j; 201 int ret = 0, j;
203 char *prop_buf; 202 char *prop_buf;
204 char *attrname; 203 char *attrname;
205 204
@@ -212,8 +211,7 @@ int power_supply_uevent(struct device *dev, char **envp, int num_envp,
212 211
213 dev_dbg(dev, "POWER_SUPPLY_NAME=%s\n", psy->name); 212 dev_dbg(dev, "POWER_SUPPLY_NAME=%s\n", psy->name);
214 213
215 ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, 214 ret = add_uevent_var(env, "POWER_SUPPLY_NAME=%s", psy->name);
216 &length, "POWER_SUPPLY_NAME=%s", psy->name);
217 if (ret) 215 if (ret)
218 return ret; 216 return ret;
219 217
@@ -243,9 +241,7 @@ int power_supply_uevent(struct device *dev, char **envp, int num_envp,
243 241
244 dev_dbg(dev, "Static prop %s=%s\n", attrname, prop_buf); 242 dev_dbg(dev, "Static prop %s=%s\n", attrname, prop_buf);
245 243
246 ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, 244 ret = add_uevent_var(env, "POWER_SUPPLY_%s=%s", attrname, prop_buf);
247 &length, "POWER_SUPPLY_%s=%s",
248 attrname, prop_buf);
249 kfree(attrname); 245 kfree(attrname);
250 if (ret) 246 if (ret)
251 goto out; 247 goto out;
@@ -282,14 +278,11 @@ int power_supply_uevent(struct device *dev, char **envp, int num_envp,
282 278
283 dev_dbg(dev, "prop %s=%s\n", attrname, prop_buf); 279 dev_dbg(dev, "prop %s=%s\n", attrname, prop_buf);
284 280
285 ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, 281 ret = add_uevent_var(env, "POWER_SUPPLY_%s=%s", attrname, prop_buf);
286 &length, "POWER_SUPPLY_%s=%s",
287 attrname, prop_buf);
288 kfree(attrname); 282 kfree(attrname);
289 if (ret) 283 if (ret)
290 goto out; 284 goto out;
291 } 285 }
292 envp[i] = NULL;
293 286
294out: 287out:
295 free_page((unsigned long)prop_buf); 288 free_page((unsigned long)prop_buf);