Re: [PATCH v11 09/14] HP BIOSCFG driver - enum-attributes

From: Jorge Lopez
Date: Thu May 04 2023 - 11:52:24 EST


On Wed, May 3, 2023 at 3:10 PM Thomas Weißschuh <thomas@xxxxxxxx> wrote:
>
> On 2023-05-03 14:42:37-0500, Jorge Lopez wrote:
> > On Sun, Apr 23, 2023 at 7:55 AM Thomas Weißschuh <thomas@xxxxxxxx> wrote:
> > >
> > > On 2023-04-20 11:54:49-0500, Jorge Lopez wrote:
> > > > .../x86/hp/hp-bioscfg/enum-attributes.c | 543 ++++++++++++++++++
> > > > 1 file changed, 543 insertions(+)
> > > > create mode 100644 drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
> > > >
> > > > diff --git a/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c b/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
>
> <snip>
>
> > > > +/*
> > > > + * validate_enumeration_input() -
> > > > + * Validate input of current_value against possible values
> > > > + *
> > > > + * @instance_id: The instance on which input is validated
> > > > + * @buf: Input value
> > > > + */
> > > > +static int validate_enumeration_input(int instance_id, const char *buf)
> > > > +{
> > > > + int ret = 0;
> > > > + int found = 0;
> > > > + int i;
> > > > + int possible_values;
> > > > +
> > > > + /* Is it a read only attribute */
> > > > + if (bioscfg_drv.enumeration_data[instance_id].common.is_readonly)
> > > > + return -EIO;
> > > > +
> > > > + possible_values = bioscfg_drv.enumeration_data[instance_id].possible_values_size;
> > > > + for (i = 0; i < possible_values && !found; i++)
> > > > + if (!strcasecmp(bioscfg_drv.enumeration_data[instance_id].possible_values[i], buf))
> > >
> > > Is this also intentionally case-insensitive?
> >
> > Yes
>
> Why? It is surprising.
>
> The behavior differs from sysfs_match_string() and friends.
> Thinking about it, this function should be able to use
> __sysfs_match_string().
>
> (Same for the ordered list type)
>

I will not be able to use sysfs_match_string() for the conditions on
how the possible values are read and allocated by hp-bioscfg driver.

1. sysfs_match_string() expects the array to be defined as const char
* const array. This definition is possible if the values are
statically assigned but not when the values are dynamically allocated.

const char * const possible_values[] = {
[VALUE1] = "Enable",
[VALUE2] = "Disable",
};
...
ret = sysfs_match_string(possible_values, buf);

2. sysfs_match_string() returns error EINVAL if the string case does
not match. sysfs_match_string() string comparison is case sensitive.

3. BIOS rejects data if the data is not case sensitive nor matches
either one of the reported possible values.


> <snip>