Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp983490rwr; Wed, 3 May 2023 08:42:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7MxjrUes9SyweyfgjsRoWhzNfkccP9bMbmYJpRG6y8ZIFOMSpemZcLgcQ4dBHod4zMwuQn X-Received: by 2002:a17:902:dac5:b0:1a6:93cc:924b with SMTP id q5-20020a170902dac500b001a693cc924bmr8174633plx.3.1683128549188; Wed, 03 May 2023 08:42:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683128549; cv=none; d=google.com; s=arc-20160816; b=MTxayniIKHb7BfRers5BRsKb1wOJnBKcZKZJRXW3tCoZfHq0EH6mbYFotBcoVyn9qk uPEzGIXdTo9hTbsiG54rwrUzQYMPadmIBQuOs+59idqaFVpzQkqAUmODOgyrVwz06BLt jq9SR+tgXj6EDlTk0eHVY8T4LXg1JRKv7GX8T6wCDOlHiaEq6Fqm5Xme099JiV6FLoab M3AxXJ7S5RUSZGcJX33E06x1o6aRnNxtCV5+kU5622is4oX63Q3vabmtLRCaVuHVw3ag t+pbtYKLxFwEWmWA0BZmZCDjqsSbOQ9rrrO1x3zOM4SQ2gY2potdPDcep3bk+rK8S+aW E8WQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=rFjqMoLMLjbtDQ/FU1cJVmttw0+g9NofP/Ycqwg6QIY=; b=i10Hbaz9dv0pYd9J4YKdeeB1gDmJGvdyLRwCF0r+30x8IgNf5xXRUorV+MGLJycwop 40iEg8WjaOcC0jzjs+2PaEl7mS9874IzTbiQG5goFX3fhVEnUsM7I1paSwJHeLsVzOrq GZmHRkL551q0K2PC9Q5S2o/nsnZQfRW4B+oY8xZ6aBgSRr0zI69RCshJ+jSZtfM+ynHr e862/XTBrnL+RprbcLFixHd8ah0taBWLBHHuK2OrJbzNx0RKNAhMk+qXybPORKRrnmLS Z6aFgjYnBDpyd+mCgXvaUef4l1NC1EzjuPYLFvL+KVXP4rghsnhRCwo5uP1OSatiAsrx /2UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="K76Ghx//"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w14-20020a170902e88e00b001a1af4f6089si32431575plg.155.2023.05.03.08.42.13; Wed, 03 May 2023 08:42:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="K76Ghx//"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230327AbjECPfr (ORCPT + 99 others); Wed, 3 May 2023 11:35:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230126AbjECPfp (ORCPT ); Wed, 3 May 2023 11:35:45 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E49A449B; Wed, 3 May 2023 08:35:43 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-4ec8eca56cfso6316820e87.0; Wed, 03 May 2023 08:35:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683128142; x=1685720142; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=rFjqMoLMLjbtDQ/FU1cJVmttw0+g9NofP/Ycqwg6QIY=; b=K76Ghx//hX9tW7hHI/FUWux51ViM4vpqlDsSH5zxXGrxB50x7VcP0uDGhcb5yU4l2A K+wTlTnsGLZnklY0cgk2lbCf09y+rJUCeXq/gV8EU7TjdDivQfqjEblksuWxJzmrHhod PUHrl5Czf2YFmHTGf3Vdy4tOQpU7SEugoCUfmNPuEnU5XYBk/+coG7UxBtliSCubq/Zl IthyxQHkwaBuzchxWcF6odTdqEMruNYfUzWGwCMNCY+YrJBsugnwxhfPAfJEOLE4yGZw KXKpYUR1VBNxQU3vmbshlprI5fxJYjy/bLHYS1V3FI0KNLK1eHfU3qgxsaX2MJ12zAJz yA1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683128142; x=1685720142; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rFjqMoLMLjbtDQ/FU1cJVmttw0+g9NofP/Ycqwg6QIY=; b=WvyZb62GR6LfHay2Vbc30KYQDSV9x7+7sGppaTibU9txJ/qYlcUA/h0ONf0W5jGwvA ZlkjvPCLcuM/FXB+InVZt0lfwomLAM970Oaq7lQiaGDCPhC2NAKorAEiiYgq1azjU2ob kZsr+8rKN7/XXFp37i/ZOM483BBIlYOgrlRdr9GIs7Wiq77ieEL2l6UnMdzHHCzUOgfR tv/n64iJdVJwSLdxl/uTJ7+UHYPqu67B0/ufGMA4wM/KEudkpce57T04KG7jyXlxRQS1 WggNBJYYqjSqA6eS/dFwIQ7fLO7FcwS7WqHOyfsyLVoe4TT2ppU5AjWzNgfKM9VfAQZ7 Oizg== X-Gm-Message-State: AC+VfDw+d7z+z2hSrz3ALySRIoQvp9E3kHK+TsAEajiWGlOBSWossAys padLn1J2C54lT4S4W88VPh85ofBeEt6cgMEplAP/yg6PQIQ= X-Received: by 2002:ac2:4d10:0:b0:4f0:1a32:ca23 with SMTP id r16-20020ac24d10000000b004f01a32ca23mr927848lfi.40.1683128141551; Wed, 03 May 2023 08:35:41 -0700 (PDT) MIME-Version: 1.0 References: <20230420165454.9517-1-jorge.lopez2@hp.com> <20230420165454.9517-5-jorge.lopez2@hp.com> <26f0a80e-d3f8-4d6c-83ff-d756abed7b6b@t-8ch.de> In-Reply-To: From: Jorge Lopez Date: Wed, 3 May 2023 10:35:14 -0500 Message-ID: Subject: Re: [PATCH v11 04/14] HP BIOSCFG driver - int-attributes To: =?UTF-8?Q?Thomas_Wei=C3=9Fschuh?= Cc: hdegoede@redhat.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 2, 2023 at 4:30=E2=80=AFPM Thomas Wei=C3=9Fschuh wrote: > > 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: > > > > > > 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-attribut= es.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 > > > > > > > +int populate_integer_elements_from_package(union acpi_object *inte= ger_obj, > > > > + int integer_obj_count, > > > > + int instance_id) > > > > +{ > > > > + char *str_value =3D NULL; > > > > + int value_len; > > > > + int ret =3D 0; > > > > + u32 size =3D 0; > > > > + u32 int_value; > > > > + int elem =3D 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.d= isplay_name_language_code)); > > > > + > > > > + for (elem =3D 1, eloc =3D 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. I am adding the following information to each attribute file for clarificat= ion. "The total number of elements (INT_ELEM_CNT) read include only data relevant to this driver and its functionality. BIOS defines the order in which each element is read. Element 0 data is not relevant to this driver hence it is ignored. For clarity, The switch statement list all element names (DISPLAY_IN_UI) which defines the order in which is read and the name matches the variable where the data is stored". > > > > > > > > > > + > > > > +int populate_integer_elements_from_buffer(u8 *buffer_ptr, u32 *buf= fer_size, > > > > + int instance_id) > > > > +{ > > > > + char *dst =3D NULL; > > > > + int elem; > > > > + int reqs; > > > > + int integer; > > > > + int size =3D 0; > > > > + int ret; > > > > + int dst_size =3D *buffer_size / sizeof(u16); > > > > + > > > > + dst =3D kcalloc(dst_size, sizeof(char), GFP_KERNEL); > > > > + if (!dst) > > > > + return -ENOMEM; > > > > + > > > > + elem =3D 0; > > > > + strscpy(bioscfg_drv.integer_data[instance_id].common.display_= name_language_code, > > > > + LANG_CODE_STR, > > > > + sizeof(bioscfg_drv.integer_data[instance_id].common.d= isplay_name_language_code)); > > > > + > > > > + for (elem =3D 1; elem < 3; elem++) { > > > > + > > > > + ret =3D get_string_from_buffer(&buffer_ptr, buffer_si= ze, dst, dst_size); > > > > + if (ret < 0) > > > > + continue; > > > > + > > > > + switch (elem) { > > > > + case VALUE: > > > > + ret =3D kstrtoint(dst, 10, &integer); > > > > + if (ret) > > > > + continue; > > > > + > > > > + bioscfg_drv.integer_data[instance_id].current= _value =3D integer; > > > > + break; > > > > + case PATH: > > > > + strscpy(bioscfg_drv.integer_data[instance_id]= .common.path, dst, > > > > + sizeof(bioscfg_drv.integer_data[insta= nce_id].common.path)); > > > > + break; > > > > + default: > > > > + pr_warn("Invalid element: %d found in Integer= attribute or data may be malformed\n", elem); > > > > + break; > > > > + } > > > > + } > > > > + > > > > + for (elem =3D 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 =3D read_int_from_buf(&buffer_ptr); > > > instance.common.display_in_ui =3D read_int_from_buf(&buffer_ptr); > > > instance.common.requires_physical_presence =3D read_int_from_buf(&buf= fer_ptr); > > The proposed pattern above, just regular function calls, are also > executed in the correct order, the order in which they are written. > The code will be easier to follow and will not require checking of the results because failing conditions are ignored. This will be a good option for functions such populate_integer_elements_from_buffer(). Buffer elements. Refactoring package function, populate_integer_elements_from_package(), will introduce additional complexity and obfuscation. > 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 =3D 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 =3D 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 =3D &bioscfg_drv.integer_data[instanc= e_id]; > > ... > > integer_data->common.is_readonly =3D 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. Understood!