From: Jean Delvare <jdelvare@suse.de>
To: "Pali Rohár" <pali@kernel.org>
Cc: Heiner Kallweit <hkallweit1@gmail.com>, linux-i2c@vger.kernel.org
Subject: Re: [PATCH 05/10] i2c: i801: Improve is_dell_system_with_lis3lv02d
Date: Fri, 6 Aug 2021 13:26:40 +0200 [thread overview]
Message-ID: <20210806132640.4c5d4932@endymion> (raw)
In-Reply-To: <20210806104700.2plfzwtp2ajvmwfa@pali>
On Fri, 6 Aug 2021 12:47:00 +0200, Pali Rohár wrote:
> On Friday 06 August 2021 11:55:19 Jean Delvare wrote:
> > Therefore I would propose the following alternative:
> >
> > --- linux-5.13.orig/drivers/i2c/busses/i2c-i801.c 2021-08-06 11:11:44.275200299 +0200
> > +++ linux-5.13/drivers/i2c/busses/i2c-i801.c 2021-08-06 11:18:19.847469822 +0200
> > @@ -1194,7 +1194,7 @@ static acpi_status check_acpi_smo88xx_de
> >
> > kfree(info);
> >
> > - *((bool *)return_value) = true;
> > + *return_value = hid; /* Could be any address, used as true value */
> > return AE_CTRL_TERMINATE;
> >
> > smo88xx_not_found:
> > @@ -1204,13 +1204,10 @@ static acpi_status check_acpi_smo88xx_de
> >
> > static bool is_dell_system_with_lis3lv02d(void)
> > {
> > - bool found;
> > - const char *vendor;
> > + acpi_handle found = NULL;
>
> Then you should define it as: "void *found = NULL;" and not as
> acpi_handle anymore.
Oops, you are right of course. That being said, that could (should?)
already be the case with Heiner's patch.
> >
> > - vendor = dmi_get_system_info(DMI_SYS_VENDOR);
> > - if (!vendor || strcmp(vendor, "Dell Inc."))
> > + if (!dmi_match(DMI_SYS_VENDOR, "Dell Inc."))
> > return false;
> > -
> > /*
> > * Check that ACPI device SMO88xx is present and is functioning.
> > * Function acpi_get_devices() already filters all ACPI devices
> > @@ -1219,9 +1216,7 @@ static bool is_dell_system_with_lis3lv02
> > * 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);
> > + acpi_get_devices(NULL, check_acpi_smo88xx_device, NULL, &found);
> >
> > return found;
> > }
> >
> > Basically, it's Heiner's patch except for one line, the idea is to
> > return the HID string pointer (which has type char *) instead of the
> > acpi_handle. That way we don't depend on an opaque ACPI type. (I first
> > tried with the matching acpi_smo8800_ids entry but compiler complained
> > about incompatible pointer types due to the const).
> >
> > Actually, I think we could use pretty much ANY pointer. Heck, that
> > would work too:
> >
> > *return_value = &disable_features; /* Could be any address, used as true value */
> >
> > Would be kinda confusing, but the comment is supposed to address that.
> > In fact we could even do:
> >
> > *return_value = &i; /* Could be any address, used as true value */
> >
> > That's the address of a local variable on the stack, which will no
> > longer exist by the time we check it, but that's still a non-NULL
> > pointer so it would work :-D Seriously, let's not do that, simply
> > because static code analyzers would possibly complain.
>
> Ehm.. :-) Rather do not talk about other _interesting_ options. Somebody
> could listen and come up with this idea as another workaround for
> misusing ACPI functions API...
>
> Basically using random pointer values or context-valid pointers just as
> true value can cause issues of leaking pointer to context where it is
> not valid anymore. And very smart code analyzers are correct if they
> throw error that in variable is stored dangling pointer.
Fully agreed, I was only making fun of the situation, this last
proposal was absolutely not meant to be taken seriously.
--
Jean Delvare
SUSE L3 Support
next prev parent reply other threads:[~2021-08-06 11:26 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 [this message]
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=20210806132640.4c5d4932@endymion \
--to=jdelvare@suse.de \
--cc=hkallweit1@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox