Re: [PATCH 09/10] i2c: i801: Improve register_dell_lis3lv02d_i2c_device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
> ---
>  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.

> +			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 */


-- 
Jean Delvare
SUSE L3 Support



[Index of Archives]     [Linux GPIO]     [Linux SPI]     [Linux Hardward Monitoring]     [LM Sensors]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux