Skip to content

Commit

Permalink
ptp: ocp: handle error from nvmem_device_find
Browse files Browse the repository at this point in the history
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 <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
jlemon authored and kuba-moo committed Mar 30, 2022
1 parent 866b7a2 commit 8f0588e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions drivers/ptp/ptp_ocp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1214,10 +1214,9 @@ ptp_ocp_nvmem_device_get(struct ptp_ocp *bp, const void * const tag)
static inline void
ptp_ocp_nvmem_device_put(struct nvmem_device **nvmemp)
{
if (*nvmemp != NULL) {
if (!IS_ERR_OR_NULL(*nvmemp))
nvmem_device_put(*nvmemp);
*nvmemp = NULL;
}
*nvmemp = NULL;
}

static void
Expand All @@ -1241,13 +1240,15 @@ ptp_ocp_read_eeprom(struct ptp_ocp *bp)
}
if (!nvmem) {
nvmem = ptp_ocp_nvmem_device_get(bp, tag);
if (!nvmem)
goto out;
if (IS_ERR(nvmem)) {
ret = PTR_ERR(nvmem);
goto fail;
}
}
ret = nvmem_device_read(nvmem, map->off, map->len,
BP_MAP_ENTRY_ADDR(bp, map));
if (ret != map->len)
goto read_fail;
goto fail;
}

bp->has_eeprom_data = true;
Expand All @@ -1256,7 +1257,7 @@ ptp_ocp_read_eeprom(struct ptp_ocp *bp)
ptp_ocp_nvmem_device_put(&nvmem);
return;

read_fail:
fail:
dev_err(&bp->pdev->dev, "could not read eeprom: %d\n", ret);
goto out;
}
Expand Down

0 comments on commit 8f0588e

Please sign in to comment.