Skip to contentSkip to conversation

rtc: m48t59: use generic nvmem

bug report Dan Carpenter 2 participants 2 messages Feb 20, 2018 – Feb 21, 2018 Real time clock (RTC)

lore
Share & tools
lore
#0 lore raw

Hello Alexandre Belloni,

This is a semi-automatic email about new static checker warnings.

The patch ce0e0076da3e: "rtc: m48t59: use generic nvmem" from Feb 12, 2018, leads to the following Smatch complaint:

drivers/rtc/rtc-m48t59.c:409 m48t59_rtc_probe()
warn: variable dereferenced before check 'pdata' (see line 391)

drivers/rtc/rtc-m48t59.c
390 .stride = 1,
391 .size = pdata->offset,

                                ^^^^^^^^^^^^^

New dereference.

392 .reg_read = m48t59_nvram_read,
393 .reg_write = m48t59_nvram_write,
394 .priv = pdev,
395 };
396
397 /* This chip could be memory-mapped or I/O-mapped */
398 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
399 if (!res) {
400 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
401 if (!res)
402 return -EINVAL;
403 }
404
405 if (res->flags & IORESOURCE_IO) {
406 /* If we are I/O-mapped, the platform should provide
407 * the operations accessing chip registers.
408 */
409 if (!pdata || !pdata->write_byte || !pdata->read_byte)

                             ^^^^^

The existing code assumed "pdata" could be NULL.

   410				return -EINVAL;
   411		} else if (res->flags & IORESOURCE_MEM) {

regards,
dan carpenter

#1 lore raw

Hi Dan,

Thanks for the report, I'm fixing up the patch (it uncovered another issue).

Quoted 42 lines · Dan Carpenter

Hello Alexandre Belloni,

This is a semi-automatic email about new static checker warnings.

The patch ce0e0076da3e: "rtc: m48t59: use generic nvmem" from Feb 12, 2018, leads to the following Smatch complaint:

drivers/rtc/rtc-m48t59.c:409 m48t59_rtc_probe()
warn: variable dereferenced before check 'pdata' (see line 391)

drivers/rtc/rtc-m48t59.c
390 .stride = 1,
391 .size = pdata->offset,

                                ^^^^^^^^^^^^^

New dereference.

   392			.reg_read = m48t59_nvram_read,
   393			.reg_write = m48t59_nvram_write,
   394			.priv = pdev,
   395		};
   396	
   397		/* This chip could be memory-mapped or I/O-mapped */
   398		res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
   399		if (!res) {
   400			res = platform_get_resource(pdev, IORESOURCE_IO, 0);
   401			if (!res)
   402				return -EINVAL;
   403		}
   404	
   405		if (res->flags & IORESOURCE_IO) {
   406			/* If we are I/O-mapped, the platform should provide
   407			 * the operations accessing chip registers.
   408			 */
   409			if (!pdata || !pdata->write_byte || !pdata->read_byte)
                             ^^^^^

The existing code assumed "pdata" could be NULL.

   410				return -EINVAL;
   411		} else if (res->flags & IORESOURCE_MEM) {

regards,
dan carpenter

Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com