Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751503AbdFFWbq (ORCPT ); Tue, 6 Jun 2017 18:31:46 -0400 Received: from mail-vk0-f48.google.com ([209.85.213.48]:36242 "EHLO mail-vk0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751433AbdFFWbo (ORCPT ); Tue, 6 Jun 2017 18:31:44 -0400 MIME-Version: 1.0 In-Reply-To: References: From: Andy Lutomirski Date: Tue, 6 Jun 2017 15:31:22 -0700 Message-ID: Subject: Re: [PATCH v2] platform/x86: wmi-bmof: New driver to expose embedded Binary WMI MOF metadata To: Andy Lutomirski Cc: =?UTF-8?Q?Pali_Roh=C3=A1r?= , platform-driver-x86@vger.kernel.org, Andy Shevchenko , Mario Limonciello , Rafael Wysocki , "linux-kernel@vger.kernel.org" , Linux ACPI Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 891 Lines: 27 On Mon, Jun 5, 2017 at 8:16 PM, Andy Lutomirski 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