power_supply: don't allocate attrname
healthd queries this extremely frequently and attrname is allocated and de-allocated repeatedly. Use the stack space instead. Signed-off-by: Park Ju Hyung <qkrwngud825@gmail.com> Signed-off-by: Adam W. Willis <return.of.octobot@gmail.com>
This commit is contained in:
parent
26d295a1b4
commit
19d0fb968c
@ -628,29 +628,12 @@ void power_supply_init_attrs(struct device_type *dev_type)
|
||||
__power_supply_attrs[i] = &power_supply_attrs[i].attr;
|
||||
}
|
||||
|
||||
static char *kstruprdup(const char *str, gfp_t gfp)
|
||||
{
|
||||
char *ret, *ustr;
|
||||
|
||||
ustr = ret = kmalloc(strlen(str) + 1, gfp);
|
||||
|
||||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
while (*str)
|
||||
*ustr++ = toupper(*str++);
|
||||
|
||||
*ustr = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env)
|
||||
{
|
||||
struct power_supply *psy = dev_get_drvdata(dev);
|
||||
int ret = 0, j;
|
||||
char *prop_buf;
|
||||
char *attrname;
|
||||
char attrname[64];
|
||||
|
||||
if (!psy || !psy->desc) {
|
||||
dev_dbg(dev, "No power supply yet\n");
|
||||
@ -667,7 +650,8 @@ int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env)
|
||||
|
||||
for (j = 0; j < psy->desc->num_properties; j++) {
|
||||
struct device_attribute *attr;
|
||||
char *line;
|
||||
const char *str;
|
||||
char *line, *ustr;
|
||||
|
||||
attr = &power_supply_attrs[psy->desc->properties[j]];
|
||||
|
||||
@ -686,14 +670,14 @@ int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env)
|
||||
if (line)
|
||||
*line = 0;
|
||||
|
||||
attrname = kstruprdup(attr->attr.name, GFP_KERNEL);
|
||||
if (!attrname) {
|
||||
ret = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
str = attr->attr.name;
|
||||
ustr = attrname;
|
||||
while (*str)
|
||||
*ustr++ = toupper(*str++);
|
||||
|
||||
*ustr = 0;
|
||||
|
||||
ret = add_uevent_var(env, "POWER_SUPPLY_%s=%s", attrname, prop_buf);
|
||||
kfree(attrname);
|
||||
if (ret)
|
||||
goto out;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user