From: Heiner Kallweit <hkallweit1@gmail.com>
To: Jean Delvare <jdelvare@suse.de>
Cc: linux-i2c@vger.kernel.org
Subject: Re: [PATCH 09/10] i2c: i801: Improve register_dell_lis3lv02d_i2c_device
Date: Fri, 6 Aug 2021 22:49:00 +0200 [thread overview]
Message-ID: <72f456d2-8b6c-16b1-23c6-e117bbf5b3ee@gmail.com> (raw)
In-Reply-To: <20210805162309.14dbaf63@endymion>
On 05.08.2021 16:23, Jean Delvare wrote:
> On Sun, 01 Aug 2021 16:23:34 +0200, Heiner Kallweit wrote:
>> - Use an initializer for struct i2c_board_info info
>> - Use dmi_match()
>> - Simplify loop logic
>>
>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>> ---
>> drivers/i2c/busses/i2c-i801.c | 28 +++++++++-------------------
>> 1 file changed, 9 insertions(+), 19 deletions(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
>> index 958b2e14b..1ca92a1e0 100644
>> --- a/drivers/i2c/busses/i2c-i801.c
>> +++ b/drivers/i2c/busses/i2c-i801.c
>> @@ -1245,28 +1245,18 @@ static const struct {
>>
>> static void register_dell_lis3lv02d_i2c_device(struct i801_priv *priv)
>> {
>> - struct i2c_board_info info;
>> - const char *dmi_product_name;
>> + struct i2c_board_info info = { .type = "lis3lv02d" };
>
> Can it be moved to the inner loop where it is used, so that
> initialization only takes place when needed? I don't know how the
> compiler handles that, to be honest.
>
>> int i;
>>
>> - dmi_product_name = dmi_get_system_info(DMI_PRODUCT_NAME);
>> - for (i = 0; i < ARRAY_SIZE(dell_lis3lv02d_devices); ++i) {
>> - if (strcmp(dmi_product_name,
>> - dell_lis3lv02d_devices[i].dmi_product_name) == 0)
>> - break;
>> - }
>> -
>> - if (i == ARRAY_SIZE(dell_lis3lv02d_devices)) {
>> - dev_warn(&priv->pci_dev->dev,
>> - "Accelerometer lis3lv02d is present on SMBus but its"
>> - " address is unknown, skipping registration\n");
>> - return;
>> - }
>> + for (i = 0; i < ARRAY_SIZE(dell_lis3lv02d_devices); ++i)
>
> Outer block without curly braces is discouraged for readability and
> maintenance reasons (see Documentation/process/coding-style.rst section
> 3).
>
>> + if (dmi_match(DMI_PRODUCT_NAME, dell_lis3lv02d_devices[i].dmi_product_name)) {
>
> This causes dmi_get_system_info(DMI_PRODUCT_NAME) to be called for
> every iteration of the loop, slowing down the lookup. It's an exported
> function so it can't be inlined by the compiler. I know this happens
> only once, but we try to keep boot times as short as possible.
>
I'm aware of this. However we just talk about a small in-memory operation and
the performance impact should be neglectable. dmi_get_system_info() is just
the following:
const char *dmi_get_system_info(int field)
{
return dmi_ident[field];
}
EXPORT_SYMBOL(dmi_get_system_info);
I'd rate the simpler and better maintainable code higher.
But that's just a personal opinion and mileage may vary.
>> + info.addr = dell_lis3lv02d_devices[i].i2c_addr;
>> + i2c_new_client_device(&priv->adapter, &info);
>> + return;
>> + }
>>
>> - memset(&info, 0, sizeof(struct i2c_board_info));
>> - info.addr = dell_lis3lv02d_devices[i].i2c_addr;
>> - strlcpy(info.type, "lis3lv02d", I2C_NAME_SIZE);
>> - i2c_new_client_device(&priv->adapter, &info);
>> + pci_warn(priv->pci_dev,
>> + "Accelerometer lis3lv02d is present on SMBus but its address is unknown, skipping registration\n");
>> }
>>
>> /* Register optional slaves */
>
>
next prev parent reply other threads:[~2021-08-06 21:10 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-01 14:15 [PATCH 00/10] i2c: i801: Series with improvements Heiner Kallweit
2021-08-01 14:16 ` [PATCH 01/10] i2c: i801: Don't call pm_runtime_allow Heiner Kallweit
2021-08-02 12:53 ` Jean Delvare
2021-08-02 16:31 ` Heiner Kallweit
2021-08-04 13:36 ` Jarkko Nikula
2021-08-04 14:06 ` Rafael J. Wysocki
2021-08-04 19:02 ` Heiner Kallweit
2021-08-05 8:31 ` Jean Delvare
2021-08-06 14:11 ` Rafael J. Wysocki
2021-08-06 13:52 ` Rafael J. Wysocki
2021-08-06 18:34 ` Heiner Kallweit
2021-08-01 14:17 ` [PATCH 02/10] i2c: i801: Improve disabling runtime pm Heiner Kallweit
2021-08-05 8:39 ` Jean Delvare
2021-08-01 14:18 ` [PATCH 03/10] i2c: i801: Make p2sb_spinlock a mutex Heiner Kallweit
2021-08-05 8:49 ` Jean Delvare
2021-08-05 12:19 ` Mika Westerberg
2021-08-01 14:19 ` [PATCH 04/10] i2c: i801: Remove not needed debug message Heiner Kallweit
2021-08-05 8:53 ` Jean Delvare
2021-08-01 14:20 ` [PATCH 05/10] i2c: i801: Improve is_dell_system_with_lis3lv02d Heiner Kallweit
2021-08-05 9:51 ` Jean Delvare
2021-08-05 19:11 ` Pali Rohár
2021-08-05 19:42 ` Heiner Kallweit
2021-08-05 23:08 ` Pali Rohár
2021-08-06 9:55 ` Jean Delvare
2021-08-06 10:47 ` Pali Rohár
2021-08-06 11:26 ` Jean Delvare
2021-08-01 14:21 ` [PATCH 06/10] i2c: i801: Remove not needed check for PCI_COMMAND_INTX_DISABLE Heiner Kallweit
2021-08-05 10:41 ` Jean Delvare
2021-08-05 20:04 ` Heiner Kallweit
2021-08-06 8:46 ` Jean Delvare
2021-08-01 14:21 ` [PATCH 07/10] i2c: i801: Improve i801_acpi_probe/remove functions Heiner Kallweit
2021-08-05 13:38 ` Jean Delvare
2021-08-05 14:24 ` Mika Westerberg
2021-08-01 14:22 ` [PATCH 08/10] i2c: i801: Improve i801_add_mux Heiner Kallweit
2021-08-05 13:43 ` Jean Delvare
2021-08-01 14:23 ` [PATCH 09/10] i2c: i801: Improve register_dell_lis3lv02d_i2c_device Heiner Kallweit
2021-08-05 14:23 ` Jean Delvare
2021-08-06 20:49 ` Heiner Kallweit [this message]
2021-08-09 13:33 ` Jean Delvare
2021-08-09 19:11 ` Heiner Kallweit
2021-08-01 14:24 ` [PATCH 10/10] i2c: i801: Improve handling platform data for tco device Heiner Kallweit
2021-08-05 18:32 ` Jean Delvare
2021-08-05 19:44 ` Heiner Kallweit
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=72f456d2-8b6c-16b1-23c6-e117bbf5b3ee@gmail.com \
--to=hkallweit1@gmail.com \
--cc=jdelvare@suse.de \
--cc=linux-i2c@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