From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Wolfram Sang <wsa@the-dreams.de>,
linux-i2c@vger.kernel.org, Hans de Goede <hdegoede@redhat.com>,
"Rafael J . Wysocki" <rjw@rjwysocki.net>,
linux-acpi@vger.kernel.org,
Mika Westerberg <mika.westerberg@linux.intel.com>
Subject: Re: [PATCH v1] i2c: core: Protect acpi_match_device() against NULL
Date: Sun, 09 Jul 2017 16:18:19 +0300 [thread overview]
Message-ID: <1499606299.22624.315.camel@linux.intel.com> (raw)
In-Reply-To: <20170709131618.12121-1-andriy.shevchenko@linux.intel.com>
On Sun, 2017-07-09 at 16:16 +0300, Andy Shevchenko wrote:
> The commit 09b3b246acba
> ("i2c: core: Allow empty id_table in ACPI case as well")
> brought an additional check for ACPI match table entry, though missed
> NULL check for table itself.
>
> Do it here by introducing a helper i2c_acpi_match_device().
>
> Note, we rename some static function in i2c-core-acpi.c to distinguish
> with public API.
>
Wolfram, feel free to squash it into the original commit if it looks
better.
> Fixes: 09b3b246acba ("i2c: core: Allow empty id_table in ACPI case as
> well")
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> drivers/i2c/i2c-core-acpi.c | 19 +++++++++++++++----
> drivers/i2c/i2c-core-base.c | 2 +-
> drivers/i2c/i2c-core.h | 9 +++++++++
> 3 files changed, 25 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
> index 4842ec3a5451..a9126b3cda61 100644
> --- a/drivers/i2c/i2c-core-acpi.c
> +++ b/drivers/i2c/i2c-core-acpi.c
> @@ -230,6 +230,16 @@ void i2c_acpi_register_devices(struct i2c_adapter
> *adap)
> dev_warn(&adap->dev, "failed to enumerate I2C
> slaves\n");
> }
>
> +const struct acpi_device_id *
> +i2c_acpi_match_device(const struct acpi_device_id *matches,
> + struct i2c_client *client)
> +{
> + if (!(client && matches))
> + return NULL;
> +
> + return acpi_match_device(matches, &client->dev);
> +}
> +
> static acpi_status i2c_acpi_lookup_speed(acpi_handle handle, u32
> level,
> void *data, void
> **return_value)
> {
> @@ -289,7 +299,7 @@ u32 i2c_acpi_find_bus_speed(struct device *dev)
> }
> EXPORT_SYMBOL_GPL(i2c_acpi_find_bus_speed);
>
> -static int i2c_acpi_match_adapter(struct device *dev, void *data)
> +static int i2c_acpi_find_match_adapter(struct device *dev, void
> *data)
> {
> struct i2c_adapter *adapter = i2c_verify_adapter(dev);
>
> @@ -299,7 +309,7 @@ static int i2c_acpi_match_adapter(struct device
> *dev, void *data)
> return ACPI_HANDLE(dev) == (acpi_handle)data;
> }
>
> -static int i2c_acpi_match_device(struct device *dev, void *data)
> +static int i2c_acpi_find_match_device(struct device *dev, void *data)
> {
> return ACPI_COMPANION(dev) == data;
> }
> @@ -309,7 +319,7 @@ static struct i2c_adapter
> *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
> struct device *dev;
>
> dev = bus_find_device(&i2c_bus_type, NULL, handle,
> - i2c_acpi_match_adapter);
> + i2c_acpi_find_match_adapter);
> return dev ? i2c_verify_adapter(dev) : NULL;
> }
>
> @@ -317,7 +327,8 @@ static struct i2c_client
> *i2c_acpi_find_client_by_adev(struct acpi_device *adev)
> {
> struct device *dev;
>
> - dev = bus_find_device(&i2c_bus_type, NULL, adev,
> i2c_acpi_match_device);
> + dev = bus_find_device(&i2c_bus_type, NULL, adev,
> + i2c_acpi_find_match_device);
> return dev ? i2c_verify_client(dev) : NULL;
> }
>
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 45231d2257ad..ba51551c3077 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -357,7 +357,7 @@ static int i2c_device_probe(struct device *dev)
> * Tree or ACPI match table entry is supplied for the probing
> device.
> */
> if (!driver->id_table &&
> - !acpi_match_device(dev->driver->acpi_match_table,
> &client->dev) &&
> + !i2c_acpi_match_device(dev->driver->acpi_match_table,
> client) &&
> !i2c_of_match_device(dev->driver->of_match_table,
> client))
> return -ENODEV;
>
> diff --git a/drivers/i2c/i2c-core.h b/drivers/i2c/i2c-core.h
> index 3b63f5e5b89c..3d3d9bf02101 100644
> --- a/drivers/i2c/i2c-core.h
> +++ b/drivers/i2c/i2c-core.h
> @@ -31,9 +31,18 @@ int i2c_check_addr_validity(unsigned addr, unsigned
> short flags);
> int i2c_check_7bit_addr_validity_strict(unsigned short addr);
>
> #ifdef CONFIG_ACPI
> +const struct acpi_device_id *
> +i2c_acpi_match_device(const struct acpi_device_id *matches,
> + struct i2c_client *client);
> void i2c_acpi_register_devices(struct i2c_adapter *adap);
> #else /* CONFIG_ACPI */
> static inline void i2c_acpi_register_devices(struct i2c_adapter
> *adap) { }
> +static inline const struct acpi_device_id *
> +i2c_acpi_match_device(const struct acpi_device_id *matches,
> + struct i2c_client *client)
> +{
> + return NULL;
> +}
> #endif /* CONFIG_ACPI */
> extern struct notifier_block i2c_acpi_notifier;
>
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
next prev parent reply other threads:[~2017-07-09 13:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-09 13:16 [PATCH v1] i2c: core: Protect acpi_match_device() against NULL Andy Shevchenko
2017-07-09 13:18 ` Andy Shevchenko [this message]
2017-07-10 18:21 ` Wolfram Sang
2017-07-11 10:14 ` Andy Shevchenko
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=1499606299.22624.315.camel@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=hdegoede@redhat.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=mika.westerberg@linux.intel.com \
--cc=rjw@rjwysocki.net \
--cc=wsa@the-dreams.de \
/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;
as well as URLs for NNTP newsgroup(s).