Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4331693ybp; Mon, 7 Oct 2019 06:59:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqyRV0y6pTnpT1Oluktf4d466d0O45EThWlo2aw4t5MjKp7tIrYpC4pNeN6Ho3zQoZ3uO3fe X-Received: by 2002:a17:906:1801:: with SMTP id v1mr23878042eje.146.1570456796230; Mon, 07 Oct 2019 06:59:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570456796; cv=none; d=google.com; s=arc-20160816; b=xiPLGsm5Wkm/iQ+yV4YqSu+EZbPGshVcL+O7V4PmKrqbR9mxIED5xFax7CVtpSjLTP U54CDo7dAe2IxitaTWoUxh4Q8oFJZhIe20dZzWEFaYokpA17qcykxoK02OUVOEq/4oh/ g3EVOgcT60la5Oo2lL3zcHmP5UTHnkoH6YwUUwip3ojhPCce6RGcKMDYyDjo3vVELRH5 nHG+u2kOW2LfoF63/GXPWa8iY3EF9LkZwS6r06yGjWIrOHIYbGx+qTwyhPNeOZzx5nn3 a+yHxlWdfiGke4r9SagOzF4UasbcS0yCs9Z+m3s+0zNotgyk/6/XlBazBROBFfr6BPtc hcJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=ctSXe3Qibn7SwlKCbsSDIKSVJbFoB8K7abxEy4a8a2Y=; b=H70s+7kn7b+z+FiudYbwxmTEBXOaklcKwAcwWjMW6CLUJINYru1rX+MKWoYUZd1e95 U+NLsv13LBDB1NngsGQK67ywytSiSIaZ7Egw5AK+DZl5oEhCLraNsGobJHHCJTCC1Ezc i/uSwctA719IjSETeRFkzawvzyGUh5jtNlB8VoXzrcexMjUbsBiGX6xhUzAiAh3/7/Fe RJWFBnyA6yOcAmBNNiJQC46hCpejysiAQ9GhIVM4BpvIawFeUFpmO1OjNDp6koIjMf3f gYK9TPT0nYVoo36UtjOQecxZss2PsBiZm+t216ua1TyU3REAWm/q3O948ZvOY09XtpCz ED2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kDOH59OZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l45si8820845edb.18.2019.10.07.06.59.32; Mon, 07 Oct 2019 06:59:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kDOH59OZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728019AbfJGN7K (ORCPT + 99 others); Mon, 7 Oct 2019 09:59:10 -0400 Received: from mail-vs1-f66.google.com ([209.85.217.66]:34441 "EHLO mail-vs1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727442AbfJGN7J (ORCPT ); Mon, 7 Oct 2019 09:59:09 -0400 Received: by mail-vs1-f66.google.com with SMTP id d3so8968930vsr.1 for ; Mon, 07 Oct 2019 06:59:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ctSXe3Qibn7SwlKCbsSDIKSVJbFoB8K7abxEy4a8a2Y=; b=kDOH59OZ6r1FcPSXe+JGbtRsP2+75ns0l5OY5gHErPOOKope1DPRHLXTxUrkcPgf6z bLCUrMwDkb0U8f1EbVgdAYQXz+IY/WPdw2QVF8FpuYOIqlo3/g+rPGykW5dJExYIIRbs gBiPr5yJigX15w4y1wtSGnsdBzV6QSQO13RXs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ctSXe3Qibn7SwlKCbsSDIKSVJbFoB8K7abxEy4a8a2Y=; b=LmxdHFGVFTspgs4SilsqH7/d/YIurZ0t0FaKidyZWx7zpX0ZiVVznM+gu53PKNw29A zAJw5Bd34tVrzSa3vDKovlfC3Unqq4LmbaJrUxNrdZCUCXsyhGjTDDagBLJ5H6/lbyGB Rr70TUEk/P0uZg2k7Ji0Q9NoJ7/pTyWaIi953X4ahNu3ZPNxUOeuCRCIKYwohp8J71cN 8eBCJ7jxmOutM+X+YKmQrrYwPLNvi5Xs9M2JxTWWMgssBsbkF3oFlZGwZYQAE8uRVA6r TBk07WValOtLtpLYzUJufeLyFw1YaQv2LW6V6fUh/k+BqNx4i48OGsq7yhX8FyzawlgV pdjQ== X-Gm-Message-State: APjAAAXgXtR9ixU+6y9w6H4WUdFsfRcX5XHW1bByNP3exbE4lQn+2Y38 4rvc5AUSS1WytzKuCawKpB3G3Z8x1YYEdr2kzpQzzg== X-Received: by 2002:a67:2b86:: with SMTP id r128mr15828347vsr.119.1570456748312; Mon, 07 Oct 2019 06:59:08 -0700 (PDT) MIME-Version: 1.0 References: <20191007071610.65714-1-cychiang@chromium.org> In-Reply-To: From: Cheng-yi Chiang Date: Mon, 7 Oct 2019 21:58:41 +0800 Message-ID: Subject: Re: [PATCH] firmware: vpd: Add an interface to read VPD value To: Guenter Roeck Cc: Tzung-Bi Shih , Linux Kernel Mailing List , ALSA development , Hung-Te Lin , Stephen Boyd , Greg Kroah-Hartman , Sean Paul , Mark Brown , Dylan Reid , Tzung-Bi Shih Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 7, 2019 at 8:27 PM Guenter Roeck wrote: > > On 10/7/19 1:03 AM, Tzung-Bi Shih wrote: > > On Mon, Oct 7, 2019 at 3:16 PM Cheng-Yi Chiang wrote: > >> > >> Add an interface for other driver to query VPD value. > >> This will be used for ASoC machine driver to query calibration > >> data stored in VPD for smart amplifier speaker resistor > >> calibration. > >> > >> Signed-off-by: Cheng-Yi Chiang > >> --- > >> drivers/firmware/google/vpd.c | 16 ++++++++++++++++ > >> include/linux/firmware/google/google_vpd.h | 18 ++++++++++++++++++ > >> 2 files changed, 34 insertions(+) > >> create mode 100644 include/linux/firmware/google/google_vpd.h > >> > >> diff --git a/drivers/firmware/google/vpd.c b/drivers/firmware/google/vpd.c > >> index db0812263d46..71e9d2da63be 100644 > >> --- a/drivers/firmware/google/vpd.c > >> +++ b/drivers/firmware/google/vpd.c > >> @@ -65,6 +65,22 @@ static ssize_t vpd_attrib_read(struct file *filp, struct kobject *kobp, > >> info->bin_attr.size); > >> } > >> > >> +int vpd_attribute_read_value(bool ro, const char *key, > >> + char **value, u32 value_len) > > FWIW, I don't think the "_value" in this function name adds any value, > unless there is going to be some other read function. ACK > > The API should be documented, and state clearly that the caller must release > the returned value. ACK > > >> +{ > >> + struct vpd_attrib_info *info; > >> + struct vpd_section *sec = ro ? &ro_vpd : &rw_vpd; > >> + > >> + list_for_each_entry(info, &sec->attribs, list) { > >> + if (strcmp(info->key, key) == 0) { > >> + *value = kstrndup(info->value, value_len, GFP_KERNEL); > > > > Value is not necessary a NULL-terminated string. > > kmalloc(info->bin_attr.size) and memcpy(...) would make the most > > sense. > > > kmemdup() ? ACK > > > The value_len parameter makes less sense. It seems the caller knows > > the length of the value in advance. > > Suggest to change the value_len to report the length of value. I.e. > > *value_len = info->bin_attr.size; > > > Also please check the return value for memory allocation-like > > functions (e.g. kstrndup, kmalloc) so that *value won't be NULL but > > the function returned 0. > > > >> + return 0; > >> + } > >> + } > >> + return -EINVAL; > > Maybe something like -ENOENT would be more appropriate here. > ACK > >> +} > >> +EXPORT_SYMBOL(vpd_attribute_read_value); > >> + > > I would suggest to use EXPORT_SYMBOL_GPL(). > ACK Hi Guenter, Thanks for the quick review. I'll update accordingly in v2. > >> /* > >> * vpd_section_check_key_name() > >> * > >> diff --git a/include/linux/firmware/google/google_vpd.h b/include/linux/firmware/google/google_vpd.h > >> new file mode 100644 > >> index 000000000000..6f1160f28af8 > >> --- /dev/null > >> +++ b/include/linux/firmware/google/google_vpd.h > >> @@ -0,0 +1,18 @@ > >> +/* SPDX-License-Identifier: GPL-2.0 */ > >> +/* > >> + * Google VPD interface. > >> + * > >> + * Copyright 2019 Google Inc. > >> + */ > >> + > >> +/* Interface for reading VPD value on Chrome platform. */ > >> + > >> +#ifndef __GOOGLE_VPD_H > >> +#define __GOOGLE_VPD_H > >> + > >> +#include > >> + > >> +int vpd_attribute_read_value(bool ro, const char *key, > >> + char **value, u32 value_len); > >> + > >> +#endif /* __GOOGLE_VPD_H */ > >> -- > >> 2.23.0.581.g78d2f28ef7-goog > >> > > >