Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7421911rwr; Tue, 2 May 2023 14:40:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ79yF3zfl1exu9GklbkgqUNnAIhdzOKEpQVC2yKUSj576LNeKeyFrCZ+M/hGnLZTQU5Uda5 X-Received: by 2002:a17:903:11c4:b0:1a9:7365:fc2a with SMTP id q4-20020a17090311c400b001a97365fc2amr23287227plh.26.1683063626544; Tue, 02 May 2023 14:40:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683063626; cv=none; d=google.com; s=arc-20160816; b=RtT+Qrs1lw33wpeyyEud7ox32SZuJu+ctJzq4tqKbpxyP4jn09Ngmj174cDwPya65n Go6tKt4Xn6/YHNr3cGmYBYOYSLg6UVKRU//WWJxohqmY3UP5CdFDxYnL3GcQvkprzORw dTt1w/YyJ7fodL9myqPz7oM0ASRQNuHS3CSIro9m+Zn1o+ma6nRfvPAnaJkAMTHRKFRZ 1wPW9IMSNxrE+IJBbDilRnvExiKlTyjXAH087Uczi4EzW3foORouBaP8eVWjlZV6uq2J Z0XS8lsBsjkNyArl17KuX1Ubm/iRbEa0FwbDtQJTFDcMSa66MlxKSIjxpfnzOdQDzukh nOeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=tnkDm5Et2cyJnYl5cFTELHpBjk5jVQoAQVDKL5xbScQ=; b=GnbU2U0pquKgiW3BIA6MHK0ilhvdw2x/94EWZRFP8xOa9+QTIl8QDbzN/4A1rZnVQ0 VtoBoPSuujNvk1S2UV6fxO+3ddiIo3KaEWp70lJMDvFH4eBHMXJ5k7l+n6xzMbMdiHhr JA5Q6DHftMZsmgwCthAq8HKKLQqxNzmBASQWduz3VwvJA2izAsOBXnytT3OoGQ05xNuS z3rz+SbTNQwqnqjQcCI8l1mko+x3HNlV2exNpI5ZCnTEQz4m08NjDh266n0vO7Azqb9B PqmnRxhlsh4BhkSYgVzF1yUVg2izuEeDMnQ8xm9g1UNUVpW0OTYA4SsPHU28MxnihGDg gcog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@t-8ch.de header.s=mail header.b=E5C35Woe; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k15-20020a170902c40f00b001a6a46d70ccsi2806711plk.1.2023.05.02.14.40.12; Tue, 02 May 2023 14:40:26 -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=@t-8ch.de header.s=mail header.b=E5C35Woe; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229642AbjEBVaK (ORCPT + 99 others); Tue, 2 May 2023 17:30:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbjEBVaI (ORCPT ); Tue, 2 May 2023 17:30:08 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76D0C10FE; Tue, 2 May 2023 14:30:07 -0700 (PDT) Date: Tue, 2 May 2023 23:30:05 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=t-8ch.de; s=mail; t=1683063005; bh=w+kKsFePE+hV8C+y/o423iW0bUDfnkSuaBi7WrMOCcs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=E5C35WoemlRgOkEGL5gZQN7AOg7lsqikBAcdQVKTuhlyu9/No5vo7cafSR56b1wZ4 8k57+n5vlvzFNwFy9Itgz9WSGb954pJaqZAn7vZDBPf6ARgRlInqVlWgjvY9C4lZj4 YUj79KkRnD5Rf/b4aEX4fcGLI89qRDe/n1bnRVg4= From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: Jorge Lopez 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 Message-ID: References: <20230420165454.9517-1-jorge.lopez2@hp.com> <20230420165454.9517-5-jorge.lopez2@hp.com> <26f0a80e-d3f8-4d6c-83ff-d756abed7b6b@t-8ch.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 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-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 > > > +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. > > > > > + > > > +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.