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 03/14] HP BIOSCFG driver - bioscfg
Date: Tue, 2 May 2023 23:14:07 +0200	[thread overview]
Message-ID: <e85d71dd-3836-4b06-80d8-199c59383eff@t-8ch.de> (raw)
In-Reply-To: <CAOOmCE97GmqAxhk-_2f0gpOC7VZ=k-retewj7aTRP78ud1HKrQ@mail.gmail.com>

On 2023-05-02 14:52:14-0500, Jorge Lopez wrote:
> On Sat, Apr 22, 2023 at 5:16 PM <thomas@t-8ch.de> wrote:
> >
> > On 2023-04-20 11:54:43-0500, Jorge Lopez wrote:
> > > ---
> > >  drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 961 +++++++++++++++++++
> > >  1 file changed, 961 insertions(+)
> > >  create mode 100644 drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
> > >
> > > diff --git a/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c
> > > new file mode 100644
> > > index 000000000000..4b0d4f56e65f
> > > --- /dev/null
> > > +++ b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c

<snip>

> > > +     int retval = 0;
> > > +     u8 *attr_name;
> >
> > const char *
> 
> Cannot define  attr_name as 'const char *'.  attr_name value is set
> within the function

Then use "char *". This is pointing to a NULL-terminated string,
not a number or binary data.

This is also the type used by the functions this value is passed to.

<snip>

> > > +                     retval = kobject_init_and_add(attr_name_kobj, &attr_name_ktype,
> > > +                                                   NULL, "%s", str_value);
> > > +
> > > +                     if (retval) {
> > > +                             kobject_put(attr_name_kobj);
> >
> > The kobj was not created, why does it need the kobj_put() ?
> As indicated by kobject_init_and_add ...
> 
>  * This function combines the call to kobject_init() and kobject_add().
>  *
>  * If this function returns an error, kobject_put() must be called to
>  * properly clean up the memory associated with the object.  This is the
>  * same type of error handling after a call to kobject_add() and kobject
>  * lifetime rules are the same here.

I stand corrected, thanks!

> >
> > > +                             goto err_attr_init;
> > > +                     }
> > > +
> > > +                     /* enumerate all of these attributes */
> > > +                     switch (attr_type) {
> > > +                     case HPWMI_STRING_TYPE:
> > > +                             retval = populate_string_package_data(elements,
> > > +                                                                   instance_id,
> > > +                                                                   attr_name_kobj);
> > > +                             break;
> > > +                     case HPWMI_INTEGER_TYPE:
> > > +                             retval = populate_integer_package_data(elements,
> > > +                                                                    instance_id,
> > > +                                                                    attr_name_kobj);
> > > +                             break;
> > > +                     case HPWMI_ENUMERATION_TYPE:
> > > +                             retval = populate_enumeration_package_data(elements,
> > > +                                                                        instance_id,
> > > +                                                                        attr_name_kobj);
> > > +                             break;
> > > +                     case HPWMI_ORDERED_LIST_TYPE:
> > > +                             retval = populate_ordered_list_package_data(elements,
> > > +                                                                         instance_id,
> > > +                                                                         attr_name_kobj);
> > > +                             break;
> > > +                     case HPWMI_PASSWORD_TYPE:
> > > +                             retval = populate_password_package_data(elements,
> > > +                                                                     instance_id,
> > > +                                                                     attr_name_kobj);
> > > +                             break;
> > > +                     default:
> > > +                             break;
> >
> > This default does nothing.
> >
> > > +                     }
> > > +
> > > +                     kfree(str_value);
> >
> > Why is str_value only freed down here? It has not been used for half a
> > screen of code.
> 
> Added early in the development process and failed to clean up here.
> >
> > > +             }
> >
> > else
> >
> > > +
> > > +             if (obj->type == ACPI_TYPE_BUFFER) {
> > > +
> > > +                     buffer_size = obj->buffer.length;
> > > +                     buffer_ptr = obj->buffer.pointer;
> > > +
> > > +                     retval = get_string_from_buffer(&buffer_ptr, &buffer_size, str, MAX_BUFF);
> > > +                     if (retval < 0)
> > > +                             goto err_attr_init;
> > > +
> > > +                     if (attr_type == HPWMI_PASSWORD_TYPE || attr_type == HPWMI_SECURE_PLATFORM_TYPE)
> > > +                             tmp_set = bioscfg_drv.authentication_dir_kset;
> > > +                     else
> > > +                             tmp_set = bioscfg_drv.main_dir_kset;
> >
> > There is a bunch of common logic duplicated in both the buffer and
> > package branches.
> 
> Older BIOS reports the ACPI data as objects of type ACPI_TYPE_PACKAGE
> and the associated data is reported as elements.
> Newer BIOS reports the ACPI data as objects of type ACPI_TYPE_BUFFER.
>  (actypes.h   union acpi_object)
> The code follows a common logic although the data is acquired
> differently according to the ACPI object type
> >
> > > +
> > > +                     if (kset_find_obj(tmp_set, str)) {
> > > +                             pr_warn("Duplicate attribute name found - %s\n", str);
> >
> > Also mention that it is being ignored.
> >
> > > +                             goto nextobj;
> > > +                     }
> > > +
> > > +                     /* build attribute */
> > > +                     attr_name_kobj = kzalloc(sizeof(*attr_name_kobj), GFP_KERNEL);
> > > +                     if (!attr_name_kobj) {
> > > +                             retval = -ENOMEM;
> > > +                             goto err_attr_init;
> > > +                     }
> > > +
> > > +                     attr_name_kobj->kset = tmp_set;
> > > +
> > > +                     temp_str = str;
> > > +                     if (attr_type == HPWMI_SECURE_PLATFORM_TYPE)
> > > +                             temp_str = "SPM";
> > > +
> > > +                     retval = kobject_init_and_add(attr_name_kobj,
> > > +                                                   &attr_name_ktype, NULL, "%s",
> > > +                                                   temp_str);
> > > +                     if (retval) {
> > > +                             kobject_put(attr_name_kobj);
> > > +                             goto err_attr_init;
> > > +                     }
> > > +
> > > +                     /* enumerate all of these attributes */
> > > +                     switch (attr_type) {
> > > +                     case HPWMI_STRING_TYPE:
> > > +                             retval = populate_string_buffer_data(buffer_ptr,
> > > +                                                                  &buffer_size,
> > > +                                                                  instance_id,
> > > +                                                                  attr_name_kobj);
> > > +                             break;
> > > +                     case HPWMI_INTEGER_TYPE:
> > > +                             retval = populate_integer_buffer_data(buffer_ptr,
> > > +                                                                   &buffer_size,
> > > +                                                                   instance_id,
> > > +                                                                   attr_name_kobj);
> > > +                             break;
> > > +                     case HPWMI_ENUMERATION_TYPE:
> > > +                             retval = populate_enumeration_buffer_data(buffer_ptr,
> > > +                                                                       &buffer_size,
> > > +                                                                       instance_id,
> > > +                                                                       attr_name_kobj);
> > > +                             break;
> > > +                     case HPWMI_ORDERED_LIST_TYPE:
> > > +                             retval = populate_ordered_list_buffer_data(buffer_ptr,
> > > +                                                                        &buffer_size,
> > > +                                                                        instance_id,
> > > +                                                                        attr_name_kobj);
> > > +                             break;
> > > +                     case HPWMI_PASSWORD_TYPE:
> > > +                             retval = populate_password_buffer_data(buffer_ptr,
> > > +                                                                    &buffer_size,
> > > +                                                                    instance_id,
> > > +                                                                    attr_name_kobj);
> > > +                             break;
> > > +                     default:
> > > +                             break;
> > > +                     }
> > > +             }
> >
> > What if it's neither a package nor a buffer?
> 
> we return an error if it is neither a package nor a buffer.
> 
> if (obj->type != ACPI_TYPE_PACKAGE && obj->type != ACPI_TYPE_BUFFER) {
>        pr_err("Error: Expected ACPI-package or buffer type, got:
> %d\n",  obj->type);
>        retval = -EIO;
>        goto err_attr_init;
> }

Indeed, thanks.

This could be pulled together into:

if (package)
	...
else if (buffer)
	...
else
	report error

Note:

The "Error: " prefix is unnecessary. It's already logged as pr_err().

<snip>

  reply	other threads:[~2023-05-02 21:14 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 [this message]
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
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=e85d71dd-3836-4b06-80d8-199c59383eff@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®