diff mbox series

[v2,1/9] libata: fix ata_host_alloc_pinfo()

Message ID 20210806074252.398482-2-damien.lemoal@wdc.com
State New
Headers show
Series libata cleanups and improvements | expand

Commit Message

Damien Le Moal Aug. 6, 2021, 7:42 a.m. UTC
Avoid a potential NULL pointer dereference by testing that the ATA port
info variable "pi".

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 drivers/ata/libata-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Hannes Reinecke Aug. 6, 2021, 8:49 a.m. UTC | #1
On 8/6/21 9:42 AM, Damien Le Moal wrote:
> Avoid a potential NULL pointer dereference by testing that the ATA port
> info variable "pi".
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
> ---
>  drivers/ata/libata-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
> index 61c762961ca8..ea8b91297f12 100644
> --- a/drivers/ata/libata-core.c
> +++ b/drivers/ata/libata-core.c
> @@ -5458,7 +5458,7 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev,
>  		ap->link.flags |= pi->link_flags;
>  		ap->ops = pi->port_ops;
>  
> -		if (!host->ops && (pi->port_ops != &ata_dummy_port_ops))
> +		if (!host->ops && pi && pi->port_ops != &ata_dummy_port_ops)
>  			host->ops = pi->port_ops;
>  	}
>  
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
James Bottomley Aug. 6, 2021, 2:25 p.m. UTC | #2
On Fri, 2021-08-06 at 16:42 +0900, Damien Le Moal wrote:
> Avoid a potential NULL pointer dereference by testing that the ATA
> port
> info variable "pi".
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
> ---
>  drivers/ata/libata-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
> index 61c762961ca8..ea8b91297f12 100644
> --- a/drivers/ata/libata-core.c
> +++ b/drivers/ata/libata-core.c
> @@ -5458,7 +5458,7 @@ struct ata_host *ata_host_alloc_pinfo(struct
> device *dev,
>  		ap->link.flags |= pi->link_flags;
>  		ap->ops = pi->port_ops;

Hey, pi is used here

>  
> -		if (!host->ops && (pi->port_ops !=
> &ata_dummy_port_ops))
> +		if (!host->ops && pi && pi->port_ops !=
> &ata_dummy_port_ops)

So checking it here is just going to get us a load of static checker
reports.

James
Damien Le Moal Aug. 6, 2021, 2:31 p.m. UTC | #3
On 2021/08/06 23:25, James Bottomley wrote:
> On Fri, 2021-08-06 at 16:42 +0900, Damien Le Moal wrote:
>> Avoid a potential NULL pointer dereference by testing that the ATA
>> port
>> info variable "pi".
>>
>> Reported-by: kernel test robot <lkp@intel.com>
>> Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
>> ---
>>  drivers/ata/libata-core.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
>> index 61c762961ca8..ea8b91297f12 100644
>> --- a/drivers/ata/libata-core.c
>> +++ b/drivers/ata/libata-core.c
>> @@ -5458,7 +5458,7 @@ struct ata_host *ata_host_alloc_pinfo(struct
>> device *dev,
>>  		ap->link.flags |= pi->link_flags;
>>  		ap->ops = pi->port_ops;
> 
> Hey, pi is used here
> 
>>  
>> -		if (!host->ops && (pi->port_ops !=
>> &ata_dummy_port_ops))
>> +		if (!host->ops && pi && pi->port_ops !=
>> &ata_dummy_port_ops)
> 
> So checking it here is just going to get us a load of static checker
> reports.

I got a load of static checker warnings already before sending this :)
And I got lost in that load obviously. Will check again.

> 
> James
> 
> 
>
diff mbox series

Patch

diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 61c762961ca8..ea8b91297f12 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -5458,7 +5458,7 @@  struct ata_host *ata_host_alloc_pinfo(struct device *dev,
 		ap->link.flags |= pi->link_flags;
 		ap->ops = pi->port_ops;
 
-		if (!host->ops && (pi->port_ops != &ata_dummy_port_ops))
+		if (!host->ops && pi && pi->port_ops != &ata_dummy_port_ops)
 			host->ops = pi->port_ops;
 	}