Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ptp: ocp: handle error from nvmem_device_find

nvmem_device_find returns a valid pointer or IS_ERR().
Handle this properly.

Fixes: 0cfcdd1ebcfe ("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>

authored by

Jonathan Lemon and committed by
Jakub Kicinski
8f0588e8 866b7a27

+8 -7
+8 -7
drivers/ptp/ptp_ocp.c
··· 1214 1214 static inline void 1215 1215 ptp_ocp_nvmem_device_put(struct nvmem_device **nvmemp) 1216 1216 { 1217 - if (*nvmemp != NULL) { 1217 + if (!IS_ERR_OR_NULL(*nvmemp)) 1218 1218 nvmem_device_put(*nvmemp); 1219 - *nvmemp = NULL; 1220 - } 1219 + *nvmemp = NULL; 1221 1220 } 1222 1221 1223 1222 static void ··· 1240 1241 } 1241 1242 if (!nvmem) { 1242 1243 nvmem = ptp_ocp_nvmem_device_get(bp, tag); 1243 - if (!nvmem) 1244 - goto out; 1244 + if (IS_ERR(nvmem)) { 1245 + ret = PTR_ERR(nvmem); 1246 + goto fail; 1247 + } 1245 1248 } 1246 1249 ret = nvmem_device_read(nvmem, map->off, map->len, 1247 1250 BP_MAP_ENTRY_ADDR(bp, map)); 1248 1251 if (ret != map->len) 1249 - goto read_fail; 1252 + goto fail; 1250 1253 } 1251 1254 1252 1255 bp->has_eeprom_data = true; ··· 1257 1256 ptp_ocp_nvmem_device_put(&nvmem); 1258 1257 return; 1259 1258 1260 - read_fail: 1259 + fail: 1261 1260 dev_err(&bp->pdev->dev, "could not read eeprom: %d\n", ret); 1262 1261 goto out; 1263 1262 }