Received: by 10.192.165.148 with SMTP id m20csp1500568imm; Thu, 10 May 2018 11:40:48 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrUrtjf+UPdt4t/UatOHUuYDG82XneDHJzMCnW8laOwsQTELX0ayKnT0HTlzDTtTroQ6Kx2 X-Received: by 2002:a17:902:f44:: with SMTP id 62-v6mr2402614ply.318.1525977647987; Thu, 10 May 2018 11:40:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525977647; cv=none; d=google.com; s=arc-20160816; b=vo0py0t7SouxMtC0tredEJ48MHCiMh5XN6TM1YuwM4nPi7LSJHoiKJZ7M4nzAMIUBA VMmFRyA8Iur1hTLR0j0CjTzMK5raSkhnWybRDks2I+3Mg3Ej1yYznje302C8JVIa5WVN zcUQ/CWTqywPIddzPXRCyGguDyWqemOwSiI5GEkEdlNZ4XCnls606+QRIvyHrNJcX7To 5T/S6hGoE3ZfqUd91VknDdnGfNaOMyi7KZtqp0bPcMTbJ2bAqncd2EOpWDnRUyHWWQXt p2czFClESmVj1U3pdSDEpu5/shwnuLp7GXEm+HtmLuz1z6zUrXdYfPiXGxRuSpYHUGHk IjyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=y616QUfIcm70GuG+r4zrHzUYCp2rUJpalPhC+/yoXdw=; b=bPPYfTZVCK88zf+1/N7xYVGulKqcFY0yyCwMaJ0UazewtJZNvgzqRW6wbMSEhux4hN 54LpeM7DSIN6FhX//zTbi3e2cAXixRE4VDcpUv5bsQFH0OQlij1UeUcU7wOt+Goo1/ES M1LxONju8zRg7+ubSZ9VjKlxD5LuICU9NnsW1bCA60Lec14jCgKWnfRqsHGG6MNKZtxs rlmwm2UwumKLKA2TuUUZfVSC7MmrHpjNg+RNp7Vi5lsxvPC47osUUR1RVxh65BCjNkXn P1IDfXYFQIaBRvAa2fw9Z1uYjQ0kQnkV555nKiBnEZkyhQRK3sXnTvxDE8QJtWRCjEmP ceAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=tv7OPHKA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z124-v6si1089077pgb.241.2018.05.10.11.40.33; Thu, 10 May 2018 11:40:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=tv7OPHKA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751457AbeEJSjk (ORCPT + 99 others); Thu, 10 May 2018 14:39:40 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33062 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751345AbeEJSjj (ORCPT ); Thu, 10 May 2018 14:39:39 -0400 Received: by mail-wm0-f68.google.com with SMTP id x12-v6so45183wmc.0 for ; Thu, 10 May 2018 11:39:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=y616QUfIcm70GuG+r4zrHzUYCp2rUJpalPhC+/yoXdw=; b=tv7OPHKAIsfHm3g0fT+bc/vHH8Xno7t16q2kxfIUhaIwXZeamYYGVpKYA5q5ClSuAw 9c7em8TuHBaoK1n3UmtsvhB0h+dhnLt14cTxvjMZgonrH/+Gb2zilpQsJpRfntdO/YZA F+Pokthmv6DGQ6VDojFymuz5NxudO2N7TXcvgk3MGiTENA0s3U0CjqrUYaQ2VScHFBd9 6veXgH6x9ETm8emwwfhZP7MQlXTM3Ptjt2/XHK839kVGMPe/kfI1/Igd4i+RwCmOwkCi 61MWEfRvc6EBL+zq5nvDRWNYeupEq3dlXsZAmyL687XlCYiyH8JrbRZSNUBUoD0gNcdc FIxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=y616QUfIcm70GuG+r4zrHzUYCp2rUJpalPhC+/yoXdw=; b=gZQmRUJH/gxM8IjviimRShXmlnwPLRBiuw8PyumfoPPamgky1obJ1BO4zjdqoMpF0L TA5dpzB1iYcK6NtDjf74/nFGlsmZKRKqKgCh5ohbKLx0WJ6Z0djAIwgJ/Zf/Zp1M7jUB w3LoTKFP7gVL5zwg/GxC1UxDFwBOoXqvrQvFpcqgx9/Ji6wM35Io25u1fFn3b0E3tWkB 4cc6vEsx5NrhO+f9YkWqJbzEMZPKwxLjpe05ZqzZQrofijfpVubhyVGiurIY+pUXfAw1 ABtct64f+QxMky/WZ0vwjgA0/ofAWVM4i+pBd2vPWARQfY/4dTj8bd+3nVeZPL6QDkum 8uuA== X-Gm-Message-State: ALKqPwerBLsM7cMTExN30nZeJcgC4h9SiLCQu1VFPE8v3CV/sUXVzfXx l9oNnSccpxgA4ZoDnn10MUTz9Uwe X-Received: by 2002:a1c:b408:: with SMTP id d8-v6mr73501wmf.48.1525977578005; Thu, 10 May 2018 11:39:38 -0700 (PDT) Received: from macbookpro.malat.net (bru31-1-78-225-226-121.fbx.proxad.net. [78.225.226.121]) by smtp.gmail.com with ESMTPSA id 19-v6sm2412615wrz.7.2018.05.10.11.39.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 May 2018 11:39:37 -0700 (PDT) Received: by macbookpro.malat.net (Postfix, from userid 1000) id 330F510C04FB; Thu, 10 May 2018 20:39:36 +0200 (CEST) From: Mathieu Malaterre To: Srinivas Kandagatla Cc: Mathieu Malaterre , linux-kernel@vger.kernel.org Subject: [PATCH v3] nvmem: properly handle returned value from nvmem_reg_read Date: Thu, 10 May 2018 20:39:33 +0200 Message-Id: <20180510183933.7082-1-malat@debian.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180509185724.24079-1-malat@debian.org> References: <20180509185724.24079-1-malat@debian.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Function ‘nvmem_reg_read’ can return a non zero value indicating an error. This returned value should be read and error propagated to ‘nvmem_cell_prepare_write_buffer’. Silence a gcc warning (using W=1): drivers/nvmem/core.c:1093:9: warning: variable ‘rc’ set but not used [-Wunused-but-set-variable] Signed-off-by: Mathieu Malaterre --- v3: return exact error code instead of EINVAL, tweak commit message a bit v2: prefer ERR_PTR(-EINVAL) over a simple return NULL drivers/nvmem/core.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index b05aa8e81303..1e28597138c8 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1107,6 +1107,8 @@ static void *nvmem_cell_prepare_write_buffer(struct nvmem_cell *cell, /* setup the first byte with lsb bits from nvmem */ rc = nvmem_reg_read(nvmem, cell->offset, &v, 1); + if (rc) + goto err; *b++ |= GENMASK(bit_offset - 1, 0) & v; /* setup rest of the byte if any */ @@ -1125,11 +1127,16 @@ static void *nvmem_cell_prepare_write_buffer(struct nvmem_cell *cell, /* setup the last byte with msb bits from nvmem */ rc = nvmem_reg_read(nvmem, cell->offset + cell->bytes - 1, &v, 1); + if (rc) + goto err; *p |= GENMASK(7, (nbits + bit_offset) % BITS_PER_BYTE) & v; } return buf; +err: + kfree(buf); + return ERR_PTR(rc); } /** -- 2.11.0