From: Armin Wolf Date: Sun, 30 Jul 2023 20:45:49 +0000 (+0200) Subject: platform/x86: wmi-bmof: Simplify read_bmof() X-Git-Tag: v6.6.7~2021^2~45 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=516b2754e82dca26fa13fdf7eb8dadef98dcd9c1;p=platform%2Fkernel%2Flinux-starfive.git platform/x86: wmi-bmof: Simplify read_bmof() Replace offset handling code with a single call to memory_read_from_buffer() to simplify read_bmof(). Tested on a ASUS PRIME B650-PLUS. Reviewed-by: Thomas Weißschuh Tested-by: Thomas Weißschuh Signed-off-by: Armin Wolf Link: https://lore.kernel.org/r/20230730204550.3402-2-W_Armin@gmx.de Reviewed-by: Hans de Goede Signed-off-by: Hans de Goede --- diff --git a/drivers/platform/x86/wmi-bmof.c b/drivers/platform/x86/wmi-bmof.c index d0516ca..644d2fd 100644 --- a/drivers/platform/x86/wmi-bmof.c +++ b/drivers/platform/x86/wmi-bmof.c @@ -25,25 +25,13 @@ struct bmof_priv { struct bin_attribute bmof_bin_attr; }; -static ssize_t -read_bmof(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) +static ssize_t read_bmof(struct file *filp, struct kobject *kobj, struct bin_attribute *attr, + char *buf, loff_t off, size_t count) { - struct bmof_priv *priv = - container_of(attr, struct bmof_priv, bmof_bin_attr); + struct bmof_priv *priv = container_of(attr, struct bmof_priv, bmof_bin_attr); - if (off < 0) - return -EINVAL; - - if (off >= priv->bmofdata->buffer.length) - return 0; - - if (count > priv->bmofdata->buffer.length - off) - count = priv->bmofdata->buffer.length - off; - - memcpy(buf, priv->bmofdata->buffer.pointer + off, count); - return count; + return memory_read_from_buffer(buf, count, &off, priv->bmofdata->buffer.pointer, + priv->bmofdata->buffer.length); } static int wmi_bmof_probe(struct wmi_device *wdev, const void *context)