mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <thomas@t-8ch.de>
To: Jorge Lopez <jorgealtxwork@gmail.com>
Cc: hdegoede@redhat.com, platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v11 04/14] HP BIOSCFG driver - int-attributes
Date: Tue, 2 May 2023 23:30:05 +0200	[thread overview]
Message-ID: <efafedc0-e9d3-4060-a174-dc4f33f77246@t-8ch.de> (raw)
In-Reply-To: <CAOOmCE8+Kgkm4uscYEei1+9xHiN=wd2oNtEiLeneDS+zppuYcg@mail.gmail.com>

Hi Jorge,

thanks for incorporating my feedback, I'm curious for the next revision!

The review comments are very terse but that is only to bring across
their points better. Your effort is appreciated.

On 2023-05-02 15:56:22-0500, Jorge Lopez wrote:

<snip>

> > On 2023-04-20 11:54:44-0500, Jorge Lopez wrote:
> > > ---
> > > Based on the latest platform-drivers-x86.git/for-next
> > > ---
> > >  .../x86/hp/hp-bioscfg/int-attributes.c        | 474 ++++++++++++++++++
> > >  1 file changed, 474 insertions(+)
> > >  create mode 100644 drivers/platform/x86/hp/hp-bioscfg/int-attributes.c
> > >
> > > diff --git a/drivers/platform/x86/hp/hp-bioscfg/int-attributes.c b/drivers/platform/x86/hp/hp-bioscfg/int-attributes.c
> > > new file mode 100644
> > > index 000000000000..d8ee39dac3f9
> > > --- /dev/null
> > > +++ b/drivers/platform/x86/hp/hp-bioscfg/int-attributes.c

<snip>

> > > +int populate_integer_elements_from_package(union acpi_object *integer_obj,
> > > +                                        int integer_obj_count,
> > > +                                        int instance_id)
> > > +{
> > > +     char *str_value = NULL;
> > > +     int value_len;
> > > +     int ret = 0;
> > > +     u32 size = 0;
> > > +     u32 int_value;
> > > +     int elem = 0;
> > > +     int reqs;
> > > +     int eloc;
> > > +
> > > +     if (!integer_obj)
> > > +             return -EINVAL;
> > > +
> > > +     strscpy(bioscfg_drv.integer_data[instance_id].common.display_name_language_code,
> > > +             LANG_CODE_STR,
> > > +             sizeof(bioscfg_drv.integer_data[instance_id].common.display_name_language_code));
> > > +
> > > +     for (elem = 1, eloc = 1; elem < integer_obj_count; elem++, eloc++) {
> > > +
> > > +             /* ONLY look at the first INTEGER_ELEM_CNT elements */
> >
> > Why?
> The information provided in element 0 from the package is ignored as
> directed by the BIOS team.
> Similar action is taken when reading the information from ACPI Buffer
> (populate_integer_elements_from_buffer())

This should be mentioned somewhere.

But my question was more why to we only look at INTEGER_ELEM_CNT?
It is clear to me now, but this is very convulted. See below.

<snip>

> >
> > > +
> > > +int populate_integer_elements_from_buffer(u8 *buffer_ptr, u32 *buffer_size,
> > > +                                       int instance_id)
> > > +{
> > > +     char *dst = NULL;
> > > +     int elem;
> > > +     int reqs;
> > > +     int integer;
> > > +     int size = 0;
> > > +     int ret;
> > > +     int dst_size = *buffer_size / sizeof(u16);
> > > +
> > > +     dst = kcalloc(dst_size, sizeof(char), GFP_KERNEL);
> > > +     if (!dst)
> > > +             return -ENOMEM;
> > > +
> > > +     elem = 0;
> > > +     strscpy(bioscfg_drv.integer_data[instance_id].common.display_name_language_code,
> > > +             LANG_CODE_STR,
> > > +             sizeof(bioscfg_drv.integer_data[instance_id].common.display_name_language_code));
> > > +
> > > +     for (elem = 1; elem < 3; elem++) {
> > > +
> > > +             ret = get_string_from_buffer(&buffer_ptr, buffer_size, dst, dst_size);
> > > +             if (ret < 0)
> > > +                     continue;
> > > +
> > > +             switch (elem) {
> > > +             case VALUE:
> > > +                     ret = kstrtoint(dst, 10, &integer);
> > > +                     if (ret)
> > > +                             continue;
> > > +
> > > +                     bioscfg_drv.integer_data[instance_id].current_value = integer;
> > > +                     break;
> > > +             case PATH:
> > > +                     strscpy(bioscfg_drv.integer_data[instance_id].common.path, dst,
> > > +                             sizeof(bioscfg_drv.integer_data[instance_id].common.path));
> > > +                     break;
> > > +             default:
> > > +                     pr_warn("Invalid element: %d found in Integer attribute or data may be malformed\n", elem);
> > > +                     break;
> > > +             }
> > > +     }
> > > +
> > > +     for (elem = 3; elem < INTEGER_ELEM_CNT; elem++) {
> >
> > This loop pattern seems weird to me.
> > It is not obvious that the values are read in the order of the switch()
> > branches from the buffer.
> >
> 
> The order in which the data is read from the buffer is set by BIOS.

This I understand.

> The switch statement was used to enforce the reading order of the
> elements and provide additional clarity

This is not clear from the code alone. One also needs to know the
concrete values of the enums.

> > Something more obvious would be:
> >
> > instance.common.is_readonly = read_int_from_buf(&buffer_ptr);
> > instance.common.display_in_ui = read_int_from_buf(&buffer_ptr);
> > instance.common.requires_physical_presence = read_int_from_buf(&buffer_ptr);

The proposed pattern above, just regular function calls, are also
executed in the correct order, the order in which they are written.

For a reader it is clear that the order is important and part of the
ABI of the BIOS.

> > This would make it clear that these are fields read in order from the
> > buffer. Without having to also look at the numeric values of the
> > defines.
> >
> > Furthermore it would make the code shorter and errorhandling would be
> > clearer and the API similar to the netlink APIs.
> >
> > Or maybe with error reporting:
> >
> > ret = read_int_from_buf(&buffer_ptr, &instance.common.is_readonly);
> > if (ret)
> >     ...
> 
> Instance.common.is_readonly is only evaluated when the user attempt to
> update an attribute current value

is_readonly was only an example on how to more nicely read the data from
the buffer. It applies to all values of all attribute types.

> > ret = read_int_from_buf(&buffer_ptr, &instance.common.display_in_ui);
> > if (ret)
> >     ...
> 
> Instance.common.display_in_ui has no specific use at this time.
> 
> The code was made shorter and easier to understand by replacing the
> long statements with
> 
> struct integer_data *integer_data = &bioscfg_drv.integer_data[instance_id];
> ...
> integer_data->common.is_readonly = integer;
> 
> Same approach was taken for all attribute files.

Thanks!

Please do try to use the "plain functioncall" pattern as outlined above.
I think it can make the code much shorter and idiomatic.

  reply	other threads:[~2023-05-02 21:30 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-20 16:54 [PATCH v11 00/14] HP BIOSCFG driver Jorge Lopez
2023-04-20 16:54 ` [PATCH v11 01/14] HP BIOSCFG driver - Documentation Jorge Lopez
2023-04-22 20:50   ` Thomas Weißschuh
2023-04-24 16:11     ` Jorge Lopez
2023-04-24 20:52       ` Thomas Weißschuh
2023-04-24 21:35         ` Jorge Lopez
2023-04-26 13:04   ` Hans de Goede
2023-04-20 16:54 ` [PATCH v11 02/14] HP BIOSCFG driver - biosattr-interface Jorge Lopez
2023-04-22 21:30   ` Thomas Weißschuh
2023-04-24 20:33     ` Jorge Lopez
2023-04-24 21:04       ` Thomas Weißschuh
2023-04-24 21:49         ` Jorge Lopez
2023-04-24 22:14           ` Jorge Lopez
2023-04-25  5:28             ` Thomas Weißschuh
2023-04-25 13:39               ` Jorge Lopez
2023-04-20 16:54 ` [PATCH v11 03/14] HP BIOSCFG driver - bioscfg Jorge Lopez
2023-04-22 22:16   ` thomas
2023-05-02 19:52     ` Jorge Lopez
2023-05-02 21:14       ` Thomas Weißschuh
2023-05-02 21:36         ` Jorge Lopez
2023-04-20 16:54 ` [PATCH v11 04/14] HP BIOSCFG driver - int-attributes Jorge Lopez
2023-04-22 22:43   ` Thomas Weißschuh
2023-05-02 20:56     ` Jorge Lopez
2023-05-02 21:30       ` Thomas Weißschuh [this message]
2023-05-03 15:35         ` Jorge Lopez
2023-04-20 16:54 ` [PATCH v11 05/14] HP BIOSCFG driver - ordered-attributes Jorge Lopez
2023-04-23  6:54   ` thomas
2023-05-05 16:09     ` Jorge Lopez
2023-05-05 21:11       ` Thomas Weißschuh
2023-05-05 21:57         ` Jorge Lopez
2023-05-06  5:51           ` Thomas Weißschuh
2023-05-08 13:56             ` Jorge Lopez
2023-05-08 20:50               ` Thomas Weißschuh
2023-05-08 21:25                 ` Jorge Lopez
2023-05-09 18:38                 ` Jorge Lopez
2023-04-20 16:54 ` [PATCH v11 06/14] HP BIOSCFG driver - passwdobj-attributes Jorge Lopez
2023-04-23  9:07   ` thomas
2023-04-26 13:13     ` Hans de Goede
2023-05-04 20:29     ` Jorge Lopez
2023-05-04 20:59       ` Thomas Weißschuh
2023-05-04 21:34         ` Jorge Lopez
2023-05-04 22:21           ` Thomas Weißschuh
2023-05-05 14:30             ` Jorge Lopez
2023-04-20 16:54 ` [PATCH v11 07/14] HP BIOSCFG driver - string-attributes Jorge Lopez
2023-04-20 16:54 ` [PATCH v11 08/14] HP BIOSCFG driver - bioscfg-h Jorge Lopez
2023-04-23 12:01   ` Thomas Weißschuh
2023-04-28 15:24     ` Jorge Lopez
2023-04-28 15:36       ` Thomas Weißschuh
2023-04-28 16:03         ` Jorge Lopez
2023-04-28 16:09           ` Thomas Weißschuh
2023-04-28 16:19             ` Jorge Lopez
2023-04-28 16:30               ` Thomas Weißschuh
2023-04-28 19:38                 ` Jorge Lopez
2023-04-20 16:54 ` [PATCH v11 09/14] HP BIOSCFG driver - enum-attributes Jorge Lopez
2023-04-23 12:55   ` Thomas Weißschuh
2023-05-03 19:42     ` Jorge Lopez
2023-05-03 20:10       ` Thomas Weißschuh
2023-05-03 21:08         ` Jorge Lopez
2023-05-04 15:51         ` Jorge Lopez
2023-04-20 16:54 ` [PATCH v11 10/14] HP BIOSCFG driver - passwdattr-interface Jorge Lopez
2023-04-23 12:58   ` Thomas Weißschuh
2023-05-03 21:16     ` Jorge Lopez
2023-04-20 16:54 ` [PATCH v11 11/14] HP BIOSCFG driver - spmobj-attributes Jorge Lopez
2023-04-23  9:24   ` thomas
2023-05-03 19:34     ` Jorge Lopez
2023-04-20 16:54 ` [PATCH v11 12/14] HP BIOSCFG driver - surestart-attributes Jorge Lopez
2023-04-23 12:16   ` Thomas Weißschuh
2023-04-27 22:17     ` Jorge Lopez
2023-04-28  6:03       ` Thomas Weißschuh
2023-04-28 14:58         ` Jorge Lopez
2023-04-28 15:21           ` Thomas Weißschuh
2023-04-28 15:40             ` Jorge Lopez
2023-04-28 16:06               ` Thomas Weißschuh
2023-04-28 16:12                 ` Jorge Lopez
2023-04-28 20:46                 ` Jorge Lopez
2023-04-20 16:54 ` [PATCH v11 13/14] HP BIOSCFG driver - Makefile Jorge Lopez
2023-05-04 11:59   ` kernel test robot
2023-05-04 13:45     ` Jorge Lopez
2023-04-20 16:54 ` [PATCH v11 14/14] HP BIOSCFG driver - MAINTAINERS Jorge Lopez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=efafedc0-e9d3-4060-a174-dc4f33f77246@t-8ch.de \
    --to=thomas@t-8ch.de \
    --cc=hdegoede@redhat.com \
    --cc=jorgealtxwork@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®