diff mbox

[v2,2/6] ACPI / bus: Do not traverse through non-existed device table

Message ID 20180201202012.36524-2-andriy.shevchenko@linux.intel.com (mailing list archive)
State Changes Requested
Headers show

Commit Message

Andy Shevchenko Feb. 1, 2018, 8:20 p.m. UTC
When __acpi_match_device() is called it would be possible to have
ACPI ID table a MULL pointer. To avoid potential dereference,
check for this before traverse.

While here, remove redundant 'else'.

Fixes: 80212a162329 ("ACPI / bus: Introduce acpi_get_match_data() function")
Cc: Sinan Kaya <okaya@codeaurora.org>
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Vinod Koul <vinod.koul@intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: new patch
 drivers/acpi/bus.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Sinan Kaya Feb. 1, 2018, 8:32 p.m. UTC | #1
On 2/1/2018 3:20 PM, Andy Shevchenko wrote:
> When __acpi_match_device() is called it would be possible to have
> ACPI ID table a MULL pointer. To avoid potential dereference,

NULL

> check for this before traverse.
> 
> While here, remove redundant 'else'.
> 
> Fixes: 80212a162329 ("ACPI / bus: Introduce acpi_get_match_data() function")
> Cc: Sinan Kaya <okaya@codeaurora.org>
> Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
> Cc: Vinod Koul <vinod.koul@intel.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> v2: new patch
>  drivers/acpi/bus.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
> index a87a97bf75f8..f3a7c29e9190 100644
> --- a/drivers/acpi/bus.c
> +++ b/drivers/acpi/bus.c
> @@ -745,11 +745,13 @@ static const struct acpi_device_id *__acpi_match_device(
>  
>  	list_for_each_entry(hwid, &device->pnp.ids, list) {
>  		/* First, check the ACPI/PNP IDs provided by the caller. */
> -		for (id = ids; id->id[0] || id->cls; id++) {
> -			if (id->id[0] && !strcmp((char *) id->id, hwid->id))
> -				return id;
> -			else if (id->cls && __acpi_match_device_cls(id, hwid))
> -				return id;
> +		if (ids) {
> +			for (id = ids; id->id[0] || id->cls; id++) {
> +				if (id->id[0] && !strcmp((char *)id->id, hwid->id))
> +					return id;
> +				if (id->cls && __acpi_match_device_cls(id, hwid))
> +					return id;
> +			}
>  		}
>  
>  		/*
> 

Why not bail out here immediately if ids is null?

__acpi_match_device()
{
	/*
	 * If the device is not present, it is unnecessary to load device
	 * driver for it.
	 */
	if (!device || !device->status.present)
		return NULL;
}
Andy Shevchenko Feb. 1, 2018, 8:40 p.m. UTC | #2
On Thu, 2018-02-01 at 15:32 -0500, Sinan Kaya wrote:
> On 2/1/2018 3:20 PM, Andy Shevchenko wrote:
> > When __acpi_match_device() is called it would be possible to have
> > ACPI ID table a MULL pointer. To avoid potential dereference,
> 
> NULL

Thanks, will fix later.

> Why not bail out here immediately if ids is null?

Because of the code which wasn't in context of this patch.

See also patch 1 in the series.

It's about how acpi_driver_match_device() uses it.
Andy Shevchenko Feb. 1, 2018, 8:45 p.m. UTC | #3
On Thu, 2018-02-01 at 22:40 +0200, Andy Shevchenko wrote:
> On Thu, 2018-02-01 at 15:32 -0500, Sinan Kaya wrote:
> > On 2/1/2018 3:20 PM, Andy Shevchenko wrote:
> > > When __acpi_match_device() is called it would be possible to have
> > > ACPI ID table a MULL pointer. To avoid potential dereference,
> > 
> > NULL
> 
> Thanks, will fix later.
> 
> > Why not bail out here immediately if ids is null?
> 
> Because of the code which wasn't in context of this patch.
> 
> See also patch 1 in the series.
> 
> It's about how acpi_driver_match_device() uses it.

Btw, it makes device_get_match_data() to work properly on PRP0001 kind
of devices.
Rafael J. Wysocki Feb. 4, 2018, 7:18 a.m. UTC | #4
On Thu, Feb 1, 2018 at 9:45 PM, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> On Thu, 2018-02-01 at 22:40 +0200, Andy Shevchenko wrote:
>> On Thu, 2018-02-01 at 15:32 -0500, Sinan Kaya wrote:
>> > On 2/1/2018 3:20 PM, Andy Shevchenko wrote:
>> > > When __acpi_match_device() is called it would be possible to have
>> > > ACPI ID table a MULL pointer. To avoid potential dereference,
>> >
>> > NULL
>>
>> Thanks, will fix later.
>>
>> > Why not bail out here immediately if ids is null?
>>
>> Because of the code which wasn't in context of this patch.
>>
>> See also patch 1 in the series.
>>
>> It's about how acpi_driver_match_device() uses it.
>
> Btw, it makes device_get_match_data() to work properly on PRP0001 kind
> of devices.

Maybe combine this one with the [1/6] then, it would make it somewhat
easier to follow what's going on.
--
To unsubscribe from this list: send the line "unsubscribe dmaengine" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Andy Shevchenko Feb. 5, 2018, 3:56 p.m. UTC | #5
On Sun, 2018-02-04 at 08:18 +0100, Rafael J. Wysocki wrote:
> On Thu, Feb 1, 2018 at 9:45 PM, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > On Thu, 2018-02-01 at 22:40 +0200, Andy Shevchenko wrote:
> > > On Thu, 2018-02-01 at 15:32 -0500, Sinan Kaya wrote:
> > > > On 2/1/2018 3:20 PM, Andy Shevchenko wrote:
> > > > > When __acpi_match_device() is called it would be possible to
> > > > > have
> > > > > ACPI ID table a MULL pointer. To avoid potential dereference,
> > > > 
> > > > NULL
> > > 
> > > Thanks, will fix later.
> > > 
> > > > Why not bail out here immediately if ids is null?
> > > 
> > > Because of the code which wasn't in context of this patch.
> > > 
> > > See also patch 1 in the series.
> > > 
> > > It's about how acpi_driver_match_device() uses it.
> > 
> > Btw, it makes device_get_match_data() to work properly on PRP0001
> > kind
> > of devices.
> 
> Maybe combine this one with the [1/6] then, it would make it somewhat
> easier to follow what's going on.

Sure, I will fold in.
Andy Shevchenko Feb. 5, 2018, 3:59 p.m. UTC | #6
On Mon, 2018-02-05 at 17:56 +0200, Andy Shevchenko wrote:
> On Sun, 2018-02-04 at 08:18 +0100, Rafael J. Wysocki wrote:
> > On Thu, Feb 1, 2018 at 9:45 PM, Andy Shevchenko
> > 

> > Maybe combine this one with the [1/6] then, it would make it
> > somewhat
> > easier to follow what's going on.
> 
> Sure, I will fold in.

Ah, wait, they have different Fixes tag. One goes deeply down in the
history.

So, I can instead put more explanations in patch 1.
Would it work?
diff mbox

Patch

diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index a87a97bf75f8..f3a7c29e9190 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -745,11 +745,13 @@  static const struct acpi_device_id *__acpi_match_device(
 
 	list_for_each_entry(hwid, &device->pnp.ids, list) {
 		/* First, check the ACPI/PNP IDs provided by the caller. */
-		for (id = ids; id->id[0] || id->cls; id++) {
-			if (id->id[0] && !strcmp((char *) id->id, hwid->id))
-				return id;
-			else if (id->cls && __acpi_match_device_cls(id, hwid))
-				return id;
+		if (ids) {
+			for (id = ids; id->id[0] || id->cls; id++) {
+				if (id->id[0] && !strcmp((char *)id->id, hwid->id))
+					return id;
+				if (id->cls && __acpi_match_device_cls(id, hwid))
+					return id;
+			}
 		}
 
 		/*