drivers/rtc/rtc-nct3018y.c:112 nct3018y_get_alarm_mode() error: we previously assumed 'alarm_enable' could be null (see line 96)

From: Dan Carpenter
Date: Wed May 17 2023 - 13:34:59 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: f1fcbaa18b28dec10281551dfe6ed3a3ed80e3d6
commit: 5adbaed16cc63542057627642d2414f603f2db69 rtc: Add NCT3018Y real time clock driver
config: microblaze-randconfig-m031-20230517
compiler: microblaze-linux-gcc (GCC) 12.1.0

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Reported-by: Dan Carpenter <error27@xxxxxxxxx>
| Closes: https://lore.kernel.org/r/202305180042.DEzW1pSd-lkp@xxxxxxxxx/

smatch warnings:
drivers/rtc/rtc-nct3018y.c:112 nct3018y_get_alarm_mode() error: we previously assumed 'alarm_enable' could be null (see line 96)
drivers/rtc/rtc-nct3018y.c:112 nct3018y_get_alarm_mode() error: we previously assumed 'alarm_flag' could be null (see line 104)

vim +/alarm_enable +112 drivers/rtc/rtc-nct3018y.c

5adbaed16cc635 Mia Lin 2022-07-13 91 static int nct3018y_get_alarm_mode(struct i2c_client *client, unsigned char *alarm_enable,
5adbaed16cc635 Mia Lin 2022-07-13 92 unsigned char *alarm_flag)
5adbaed16cc635 Mia Lin 2022-07-13 93 {
5adbaed16cc635 Mia Lin 2022-07-13 94 int flags;
5adbaed16cc635 Mia Lin 2022-07-13 95
5adbaed16cc635 Mia Lin 2022-07-13 @96 if (alarm_enable) {
^^^^^^^^^^^^
If these are NULL

5adbaed16cc635 Mia Lin 2022-07-13 97 dev_dbg(&client->dev, "%s:NCT3018Y_REG_CTRL\n", __func__);
5adbaed16cc635 Mia Lin 2022-07-13 98 flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CTRL);
5adbaed16cc635 Mia Lin 2022-07-13 99 if (flags < 0)
5adbaed16cc635 Mia Lin 2022-07-13 100 return flags;
5adbaed16cc635 Mia Lin 2022-07-13 101 *alarm_enable = flags & NCT3018Y_BIT_AIE;
5adbaed16cc635 Mia Lin 2022-07-13 102 }
5adbaed16cc635 Mia Lin 2022-07-13 103
5adbaed16cc635 Mia Lin 2022-07-13 @104 if (alarm_flag) {
^^^^^^^^^^

5adbaed16cc635 Mia Lin 2022-07-13 105 dev_dbg(&client->dev, "%s:NCT3018Y_REG_ST\n", __func__);
5adbaed16cc635 Mia Lin 2022-07-13 106 flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_ST);
5adbaed16cc635 Mia Lin 2022-07-13 107 if (flags < 0)
5adbaed16cc635 Mia Lin 2022-07-13 108 return flags;
5adbaed16cc635 Mia Lin 2022-07-13 109 *alarm_flag = flags & NCT3018Y_BIT_AF;
5adbaed16cc635 Mia Lin 2022-07-13 110 }
5adbaed16cc635 Mia Lin 2022-07-13 111
5adbaed16cc635 Mia Lin 2022-07-13 @112 dev_dbg(&client->dev, "%s:alarm_enable:%x alarm_flag:%x\n",
5adbaed16cc635 Mia Lin 2022-07-13 113 __func__, *alarm_enable, *alarm_flag);
^^^^^^^^^^^^^^^^^^^^^^^^^^
The debug code will crash.

5adbaed16cc635 Mia Lin 2022-07-13 114
5adbaed16cc635 Mia Lin 2022-07-13 115 return 0;
5adbaed16cc635 Mia Lin 2022-07-13 116 }

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki