[PATCH] mtd: nand: atmel: fix of_irq_get() error check

Sergei Shtylyov sergei.shtylyov at cogentembedded.com
Thu Aug 10 03:12:09 PDT 2017


On 8/10/2017 12:59 PM, Boris Brezillon wrote:

>> of_irq_get() may return 0 as well as negative error number on failure,
>> while the driver only checks for the negative values.  The driver would
>> then call devm_request_irq() for IRQ0  in its probe method and never get
>> a valid interrupt.
>>
>> Check for 'nc->irq <= 0' instead and return -ENXIO from the driver's probe
>> iff of_irq_get() returned 0.
>>
>> Fixes: f88fc122cc34 ("mtd: nand: Cleanup/rework the atmel_nand driver")
>> Signed-off-by: Sergei Shtylyov <sergei.shtylyov at cogentembedded.com>
>>
>> ---
>> The patch is against the 'master' branch of the 'linux-mtd.git' repo --
>> the 'nand/fixes'  branch seems too old...
>>
>>   drivers/mtd/nand/atmel/nand-controller.c |   12 ++++++------
>>   1 file changed, 6 insertions(+), 6 deletions(-)
>>
>> Index: linux-mtd/drivers/mtd/nand/atmel/nand-controller.c
>> ===================================================================
>> --- linux-mtd.orig/drivers/mtd/nand/atmel/nand-controller.c
>> +++ linux-mtd/drivers/mtd/nand/atmel/nand-controller.c
>> @@ -2078,11 +2078,11 @@ atmel_hsmc_nand_controller_legacy_init(s
>>   	}
>>   
>>   	nc->irq = of_irq_get(nand_np, 0);
>> -	if (nc->irq < 0) {
>> -		ret = nc->irq;
>> -		if (ret != -EPROBE_DEFER)
>> +	if (nc->irq <= 0) {
>> +		if (nc->irq != -EPROBE_DEFER)
>>   			dev_err(dev, "Failed to get IRQ number (err = %d)\n",
>> -				ret);
>> +				nc->irq);
> 
> nc->irq can be 0 here which doesn't make any sense for an error return
> code, so I'd suggest to still use ret and move the 'ret = nc->irq ?:
> -ENXIO' line before doing the != -EPROBE_DEFER test.

    I tried to keep reporting the original of_irq_get() result. Can change it 
if you prefer it another way...

>> +		ret = nc->irq ?: -ENXIO;
> 
> Why ENXIO and not EINVAL?

    That's what platform_get_irq() (another of_irq_get() user) returns if it 
doesn't find the IRQ resource.

>>   		goto out;
>>   	}
>>   
[...]
MBR, Sergei



More information about the linux-mtd mailing list