greybus: bundle: use kstrdup() for state file
The kernfs code guarantees we'll get a NUL-terminated buffer. Use kstrdup() rather than kzalloc() + memcpy() in state_store() making it slightly clearer what we're doing. This has the added benefit of guaranteeing that the stored string has no NUL character inside it. Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>hifive-unleashed-5.1
parent
55b930cd17
commit
22fd2a8ade
|
@ -48,12 +48,10 @@ static ssize_t state_store(struct device *dev, struct device_attribute *attr,
|
||||||
struct gb_bundle *bundle = to_gb_bundle(dev);
|
struct gb_bundle *bundle = to_gb_bundle(dev);
|
||||||
|
|
||||||
kfree(bundle->state);
|
kfree(bundle->state);
|
||||||
bundle->state = kzalloc(size + 1, GFP_KERNEL);
|
bundle->state = kstrdup(buf, GFP_KERNEL);
|
||||||
if (!bundle->state)
|
if (!bundle->state)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
memcpy(bundle->state, buf, size);
|
|
||||||
|
|
||||||
/* Tell userspace that the file contents changed */
|
/* Tell userspace that the file contents changed */
|
||||||
sysfs_notify(&bundle->dev.kobj, NULL, "state");
|
sysfs_notify(&bundle->dev.kobj, NULL, "state");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue