Re: [PATCH net-next v2 1/1] ptp: clockmatrix: support 32-bit address space

From: Dan Carpenter
Date: Mon Nov 20 2023 - 05:55:07 EST


Hi Min,

kernel test robot noticed the following build warnings:

url: https://github.com/intel-lab-lkp/linux/commits/Min-Li/ptp-clockmatrix-support-32-bit-address-space/20231110-044554
base: net-next/main
patch link: https://lore.kernel.org/r/MW5PR03MB6932A4AAD4F612B45E9F6856A0AFA%40MW5PR03MB6932.namprd03.prod.outlook.com
patch subject: [PATCH net-next v2 1/1] ptp: clockmatrix: support 32-bit address space
config: i386-randconfig-141-20231111 (https://download.01.org/0day-ci/archive/20231111/202311110542.BjfgVNxz-lkp@xxxxxxxxx/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20231111/202311110542.BjfgVNxz-lkp@xxxxxxxxx/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Reported-by: Dan Carpenter <error27@xxxxxxxxx>
| Closes: https://lore.kernel.org/r/202311110542.BjfgVNxz-lkp@xxxxxxxxx/

New smatch warnings:
drivers/ptp/ptp_clockmatrix.c:1257 idtcm_load_firmware() warn: '(537972560)' 537972560 can't fit into 65535 'scratch'

vim +1257 drivers/ptp/ptp_clockmatrix.c

3a6ba7dc779935 Vincent Cheng 2019-10-31 1254 static int idtcm_load_firmware(struct idtcm *idtcm,
3a6ba7dc779935 Vincent Cheng 2019-10-31 1255 struct device *dev)
3a6ba7dc779935 Vincent Cheng 2019-10-31 1256 {
794c3dffacc166 Min Li 2021-09-13 @1257 u16 scratch = IDTCM_FW_REG(idtcm->fw_ver, V520, SCRATCH);

-#define SCRATCH_V520 0xcf4c
+#define SCRATCH_V520 0x2010cf4c

This doesn't fit into a u16 any more. I'm not sure this a bug, but it's
a bit ugly.

7ea5fda2b1325e Min Li 2020-07-28 1258 char fname[128] = FW_FILENAME;
3a6ba7dc779935 Vincent Cheng 2019-10-31 1259 const struct firmware *fw;
3a6ba7dc779935 Vincent Cheng 2019-10-31 1260 struct idtcm_fwrc *rec;
3a6ba7dc779935 Vincent Cheng 2019-10-31 1261 u32 regaddr;
3a6ba7dc779935 Vincent Cheng 2019-10-31 1262 int err;
3a6ba7dc779935 Vincent Cheng 2019-10-31 1263 s32 len;
3a6ba7dc779935 Vincent Cheng 2019-10-31 1264 u8 val;
3a6ba7dc779935 Vincent Cheng 2019-10-31 1265 u8 loaddr;
3a6ba7dc779935 Vincent Cheng 2019-10-31 1266
7ea5fda2b1325e Min Li 2020-07-28 1267 if (firmware) /* module parameter */
7ea5fda2b1325e Min Li 2020-07-28 1268 snprintf(fname, sizeof(fname), "%s", firmware);
3a6ba7dc779935 Vincent Cheng 2019-10-31 1269
930dfa56315517 Min Li 2021-09-24 1270 dev_info(idtcm->dev, "requesting firmware '%s'", fname);
3a6ba7dc779935 Vincent Cheng 2019-10-31 1271
7ea5fda2b1325e Min Li 2020-07-28 1272 err = request_firmware(&fw, fname, dev);
7ea5fda2b1325e Min Li 2020-07-28 1273 if (err) {
930dfa56315517 Min Li 2021-09-24 1274 dev_err(idtcm->dev,
1c49d3e947783b Vincent Cheng 2021-02-17 1275 "Failed at line %d in %s!", __LINE__, __func__);
3a6ba7dc779935 Vincent Cheng 2019-10-31 1276 return err;
7ea5fda2b1325e Min Li 2020-07-28 1277 }
3a6ba7dc779935 Vincent Cheng 2019-10-31 1278
930dfa56315517 Min Li 2021-09-24 1279 dev_dbg(idtcm->dev, "firmware size %zu bytes", fw->size);
3a6ba7dc779935 Vincent Cheng 2019-10-31 1280
3a6ba7dc779935 Vincent Cheng 2019-10-31 1281 rec = (struct idtcm_fwrc *) fw->data;
3a6ba7dc779935 Vincent Cheng 2019-10-31 1282
794c3dffacc166 Min Li 2021-09-13 1283 if (contains_full_configuration(idtcm, fw))
3a6ba7dc779935 Vincent Cheng 2019-10-31 1284 idtcm_state_machine_reset(idtcm);
3a6ba7dc779935 Vincent Cheng 2019-10-31 1285
3a6ba7dc779935 Vincent Cheng 2019-10-31 1286 for (len = fw->size; len > 0; len -= sizeof(*rec)) {
3a6ba7dc779935 Vincent Cheng 2019-10-31 1287 if (rec->reserved) {
930dfa56315517 Min Li 2021-09-24 1288 dev_err(idtcm->dev,
1c49d3e947783b Vincent Cheng 2021-02-17 1289 "bad firmware, reserved field non-zero");
3a6ba7dc779935 Vincent Cheng 2019-10-31 1290 err = -EINVAL;
3a6ba7dc779935 Vincent Cheng 2019-10-31 1291 } else {
3a6ba7dc779935 Vincent Cheng 2019-10-31 1292 regaddr = rec->hiaddr << 8;
3a6ba7dc779935 Vincent Cheng 2019-10-31 1293 regaddr |= rec->loaddr;
3a6ba7dc779935 Vincent Cheng 2019-10-31 1294
3a6ba7dc779935 Vincent Cheng 2019-10-31 1295 val = rec->value;
3a6ba7dc779935 Vincent Cheng 2019-10-31 1296 loaddr = rec->loaddr;
3a6ba7dc779935 Vincent Cheng 2019-10-31 1297
3a6ba7dc779935 Vincent Cheng 2019-10-31 1298 rec++;
3a6ba7dc779935 Vincent Cheng 2019-10-31 1299
3a6ba7dc779935 Vincent Cheng 2019-10-31 1300 err = check_and_set_masks(idtcm, regaddr, val);
3a6ba7dc779935 Vincent Cheng 2019-10-31 1301 }
3a6ba7dc779935 Vincent Cheng 2019-10-31 1302
7ea5fda2b1325e Min Li 2020-07-28 1303 if (err != -EINVAL) {
7ea5fda2b1325e Min Li 2020-07-28 1304 err = 0;
7ea5fda2b1325e Min Li 2020-07-28 1305
3a6ba7dc779935 Vincent Cheng 2019-10-31 1306 /* Top (status registers) and bottom are read-only */
9fe9b9792d7236 Min Li 2023-11-09 1307 if (regaddr < SCSR_ADDR(GPIO_USER_CONTROL) || regaddr >= scratch)
3a6ba7dc779935 Vincent Cheng 2019-10-31 1308 continue;
3a6ba7dc779935 Vincent Cheng 2019-10-31 1309
3a6ba7dc779935 Vincent Cheng 2019-10-31 1310 /* Page size 128, last 4 bytes of page skipped */
77fdb168a3e2a6 Vincent Cheng 2021-02-17 1311 if ((loaddr > 0x7b && loaddr <= 0x7f) || loaddr > 0xfb)
3a6ba7dc779935 Vincent Cheng 2019-10-31 1312 continue;
3a6ba7dc779935 Vincent Cheng 2019-10-31 1313
9fe9b9792d7236 Min Li 2023-11-09 1314 err = idtcm_write(idtcm, SCSR_BASE, regaddr, &val, sizeof(val));
3a6ba7dc779935 Vincent Cheng 2019-10-31 1315 }
3a6ba7dc779935 Vincent Cheng 2019-10-31 1316
3a6ba7dc779935 Vincent Cheng 2019-10-31 1317 if (err)
3a6ba7dc779935 Vincent Cheng 2019-10-31 1318 goto out;
3a6ba7dc779935 Vincent Cheng 2019-10-31 1319 }
3a6ba7dc779935 Vincent Cheng 2019-10-31 1320
7ea5fda2b1325e Min Li 2020-07-28 1321 display_pll_and_masks(idtcm);
3a6ba7dc779935 Vincent Cheng 2019-10-31 1322
3a6ba7dc779935 Vincent Cheng 2019-10-31 1323 out:
3a6ba7dc779935 Vincent Cheng 2019-10-31 1324 release_firmware(fw);
3a6ba7dc779935 Vincent Cheng 2019-10-31 1325 return err;
3a6ba7dc779935 Vincent Cheng 2019-10-31 1326 }

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