From: Alex Elder Date: Fri, 17 Apr 2015 19:41:47 +0000 (-0500) Subject: greybus: bundle: use kstrdup() for state file X-Git-Tag: android-x86-7.1-r1~621^2~378^2~21^2~1575 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=22fd2a8ade59bb97f0a64282ba5b3903ba3e9e89;p=android-x86%2Fkernel.git 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 Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/greybus/bundle.c b/drivers/staging/greybus/bundle.c index e7b2199f39b4..2047e173ebd9 100644 --- a/drivers/staging/greybus/bundle.c +++ b/drivers/staging/greybus/bundle.c @@ -48,12 +48,10 @@ static ssize_t state_store(struct device *dev, struct device_attribute *attr, struct gb_bundle *bundle = to_gb_bundle(dev); kfree(bundle->state); - bundle->state = kzalloc(size + 1, GFP_KERNEL); + bundle->state = kstrdup(buf, GFP_KERNEL); if (!bundle->state) return -ENOMEM; - memcpy(bundle->state, buf, size); - /* Tell userspace that the file contents changed */ sysfs_notify(&bundle->dev.kobj, NULL, "state");