All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heiner Kallweit <hkallweit1@gmail.com>
To: "Pali Rohár" <pali@kernel.org>, "Jean Delvare" <jdelvare@suse.de>
Cc: linux-i2c@vger.kernel.org
Subject: Re: [PATCH 05/10] i2c: i801: Improve is_dell_system_with_lis3lv02d
Date: Thu, 5 Aug 2021 21:42:23 +0200	[thread overview]
Message-ID: <14a49ba2-f6a6-3ccc-6a65-70a72bb3fe51@gmail.com> (raw)
In-Reply-To: <20210805191144.qq37e73p5zqomkem@pali>

On 05.08.2021 21:11, Pali Rohár wrote:
> Hello!
> 
> On Thursday 05 August 2021 11:51:56 Jean Delvare wrote:
>> Hi Heiner,
>>
>> On Sun, 01 Aug 2021 16:20:19 +0200, Heiner Kallweit wrote:
>>> Replace the ugly cast of the return_value pointer with proper usage.
>>> In addition use dmi_match() instead of open-coding it.
>>
>> Pali, would you be able to test this patch?
> 
> Tested now on Latitude E6440 and patch is working fine (no difference).
> 
>>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>>> ---
>>>  drivers/i2c/busses/i2c-i801.c | 13 ++++---------
>>>  1 file changed, 4 insertions(+), 9 deletions(-)
>>>
>>> diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
>>> index d971ee20c..a6287c520 100644
>>> --- a/drivers/i2c/busses/i2c-i801.c
>>> +++ b/drivers/i2c/busses/i2c-i801.c
>>> @@ -1191,7 +1191,7 @@ static acpi_status check_acpi_smo88xx_device(acpi_handle obj_handle,
>>>  
>>>  	kfree(info);
>>>  
>>> -	*((bool *)return_value) = true;
>>> +	*return_value = obj_handle;
> 
> You are missing a cast here. "obj_handle" is of unknown typedef type
> acpi_handle and *return_value is of type void*. So this can generate a
> compile warning (either now or in future).
> 

acpi_handle is defined as:  typedef void *acpi_handle;
Therefore compiler is happy (as long as acpi_handle is any pointer type).

> So you need to write it something like this:
> 
>   *((acpi_handle *)return_value) = obj_handle;
> 
> But what is benefit of this change? Is not usage of explicit true and
> false values better than some acpi_handle type of undefined value stored
> in obj_handle?
> 
>From a logical perspective I agree. My motivation is that I see explicit
casts as a last resort and try to avoid them as far as possible.
The current code abuses a void* variable to store a bool. This makes the
implicit assumption that a pointer variable is always big enough to
store a bool.

With regard to "acpi_handle of undefined value": I'm just interested
in the information whether handle is NULL or not. That's the normal
implicit cast to bool like in every if(pointer) clause. 

>>>  	return AE_CTRL_TERMINATE;
>>>  
>>>  smo88xx_not_found:
>>> @@ -1201,13 +1201,10 @@ static acpi_status check_acpi_smo88xx_device(acpi_handle obj_handle,
>>>  
>>>  static bool is_dell_system_with_lis3lv02d(void)
>>>  {
>>> -	bool found;
>>> -	const char *vendor;
>>> +	acpi_handle found = NULL;
> 
> Anyway, it looks strange to use name "found" for object handle
> variable. I would expect that something named "found" is storing
> something which refers to 2-state logic and not some handle value.
> 
>>>  
>>> -	vendor = dmi_get_system_info(DMI_SYS_VENDOR);
>>> -	if (!vendor || strcmp(vendor, "Dell Inc."))
>>> +	if (!dmi_match(DMI_SYS_VENDOR, "Dell Inc."))
>>>  		return false;
>>
>> Looks good to me.
>>
>>> -
>>
>> I see no reason to remove that blank line.
>>
>>>  	/*
>>>  	 * Check that ACPI device SMO88xx is present and is functioning.
>>>  	 * Function acpi_get_devices() already filters all ACPI devices
>>> @@ -1216,9 +1213,7 @@ static bool is_dell_system_with_lis3lv02d(void)
>>>  	 * accelerometer but unfortunately ACPI does not provide any other
>>>  	 * information (like I2C address).
>>>  	 */
>>> -	found = false;
>>> -	acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL,
>>> -			 (void **)&found);
> 
> Just to explain my motivation: I originally assigned found to false
> value immediately before acpi_get_devices() function call to show that
> this is the place where variable is used due to to API of that function.
> 
>>> +	acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL, &found);
>>
>> The choice of return value by the acpi_get_devices() designer is very
>> unfortunate. It would have been much more convenient if the return
>> value was different whether a match has been found or not. Oh well.
> 
> I agree, it is very _original_ way...
> 
>> I agree that the proposed change is a nicer way to work around this
>> limitation. Unfortunately I can't test this as I do not own a Dell
>> laptop. Were you able to test it? If not, I hope Pali will.
>>
>>>  
>>>  	return found;
>>>  }
>>
>> Reviewed-by: Jean Delvare <jdelvare@suse.de>
>>
>> -- 
>> Jean Delvare
>> SUSE L3 Support


  reply	other threads:[~2021-08-05 20:06 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 [this message]
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
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=14a49ba2-f6a6-3ccc-6a65-70a72bb3fe51@gmail.com \
    --to=hkallweit1@gmail.com \
    --cc=jdelvare@suse.de \
    --cc=linux-i2c@vger.kernel.org \
    --cc=pali@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.