Re: [PATCH v2] platform/x86: wmi-bmof: New driver to expose embedded Binary WMI MOF metadata

From: Andy Lutomirski
Date: Tue Jun 06 2017 - 18:31:49 EST


On Mon, Jun 5, 2017 at 8:16 PM, Andy Lutomirski <luto@xxxxxxxxxx> wrote:
> +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);
> +
> + 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;
> +}

I just discovered simple_read_from_buffer(). I think this whole
function could be:

struct bmof_priv *priv = ...;
return simple_read_from_buffer(buf, count, &off,
priv->bmofdata->buffer.pointer, priv->bmofdata->buffer.length);

--Andy