From patchwork Tue Mar 29 16:03:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Lemon X-Patchwork-Id: 12795032 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31A48C433EF for ; Tue, 29 Mar 2022 16:04:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239145AbiC2QFo (ORCPT ); Tue, 29 Mar 2022 12:05:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239148AbiC2QFm (ORCPT ); Tue, 29 Mar 2022 12:05:42 -0400 Received: from smtp6.emailarray.com (smtp6.emailarray.com [65.39.216.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6D8D275FD for ; Tue, 29 Mar 2022 09:03:58 -0700 (PDT) Received: (qmail 73382 invoked by uid 89); 29 Mar 2022 16:03:55 -0000 Received: from unknown (HELO localhost) (amxlbW9uQGZsdWdzdmFtcC5jb21AMTc0LjIxLjgzLjg3) (POLARISLOCAL) by smtp6.emailarray.com with SMTP; 29 Mar 2022 16:03:55 -0000 From: Jonathan Lemon To: kuba@kernel.org, davem@davemloft.net, richardcochran@gmail.com Cc: netdev@vger.kernel.org, kernel-team@fb.com Subject: [PATCH net] ptp: ocp: handle error from nvmem_device_find Date: Tue, 29 Mar 2022 09:03:54 -0700 Message-Id: <20220329160354.4035-1-jonathan.lemon@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 --- drivers/ptp/ptp_ocp.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c index c3d0fcf609e3..0feaa4b45317 100644 --- a/drivers/ptp/ptp_ocp.c +++ b/drivers/ptp/ptp_ocp.c @@ -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 @@ -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; @@ -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; }