Skip to content

Commit 8f0588e

Browse files
jlemonkuba-moo
authored andcommitted
ptp: ocp: handle error from nvmem_device_find
nvmem_device_find returns a valid pointer or IS_ERR(). Handle this properly. Fixes: 0cfcdd1 ("ptp: ocp: add nvmem interface for accessing eeprom") Signed-off-by: Jonathan Lemon <jonathan.lemon@gmail.com> Link: https://lore.kernel.org/r/20220329160354.4035-1-jonathan.lemon@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 866b7a2 commit 8f0588e

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

drivers/ptp/ptp_ocp.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,10 +1214,9 @@ ptp_ocp_nvmem_device_get(struct ptp_ocp *bp, const void * const tag)
12141214
static inline void
12151215
ptp_ocp_nvmem_device_put(struct nvmem_device **nvmemp)
12161216
{
1217-
if (*nvmemp != NULL) {
1217+
if (!IS_ERR_OR_NULL(*nvmemp))
12181218
nvmem_device_put(*nvmemp);
1219-
*nvmemp = NULL;
1220-
}
1219+
*nvmemp = NULL;
12211220
}
12221221

12231222
static void
@@ -1241,13 +1240,15 @@ ptp_ocp_read_eeprom(struct ptp_ocp *bp)
12411240
}
12421241
if (!nvmem) {
12431242
nvmem = ptp_ocp_nvmem_device_get(bp, tag);
1244-
if (!nvmem)
1245-
goto out;
1243+
if (IS_ERR(nvmem)) {
1244+
ret = PTR_ERR(nvmem);
1245+
goto fail;
1246+
}
12461247
}
12471248
ret = nvmem_device_read(nvmem, map->off, map->len,
12481249
BP_MAP_ENTRY_ADDR(bp, map));
12491250
if (ret != map->len)
1250-
goto read_fail;
1251+
goto fail;
12511252
}
12521253

12531254
bp->has_eeprom_data = true;
@@ -1256,7 +1257,7 @@ ptp_ocp_read_eeprom(struct ptp_ocp *bp)
12561257
ptp_ocp_nvmem_device_put(&nvmem);
12571258
return;
12581259

1259-
read_fail:
1260+
fail:
12601261
dev_err(&bp->pdev->dev, "could not read eeprom: %d\n", ret);
12611262
goto out;
12621263
}

0 commit comments

Comments
 (0)