lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 7 Oct 2019 05:27:51 -0700
From:   Guenter Roeck <linux@...ck-us.net>
To:     Tzung-Bi Shih <tzungbi@...gle.com>,
        Cheng-Yi Chiang <cychiang@...omium.org>
Cc:     Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        ALSA development <alsa-devel@...a-project.org>,
        Hung-Te Lin <hungte@...omium.org>,
        Stephen Boyd <swboyd@...omium.org>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Sean Paul <seanpaul@...omium.org>,
        Mark Brown <broonie@...nel.org>, dgreid@...omium.org,
        Tzung-Bi Shih <tzungbi@...omium.org>
Subject: Re: [PATCH] firmware: vpd: Add an interface to read VPD value

On 10/7/19 1:03 AM, Tzung-Bi Shih wrote:
> On Mon, Oct 7, 2019 at 3:16 PM Cheng-Yi Chiang <cychiang@...omium.org> 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 <cychiang@...omium.org>
>> ---
>>   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.

The API should be documented, and state clearly that the caller must release
the returned value.

>> +{
>> +       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() ?

> 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.

>> +}
>> +EXPORT_SYMBOL(vpd_attribute_read_value);
>> +

I would suggest to use EXPORT_SYMBOL_GPL().

>>   /*
>>    * 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 <linux/types.h>
>> +
>> +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
>>
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ