Received: by 10.192.165.148 with SMTP id m20csp247396imm; Wed, 9 May 2018 11:59:29 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqgm0Cc6pG4Eq+1jpulhVFHCfRhC6YbyJ7bkLtf6qSusar22W7aeQIorcCetkHwD2Ece8ri X-Received: by 2002:a17:902:7d87:: with SMTP id a7-v6mr15510249plm.264.1525892369049; Wed, 09 May 2018 11:59:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525892368; cv=none; d=google.com; s=arc-20160816; b=AJu/9xqhzBwdQ1tB/bymALL4eIAraVW8VWfWIN+6ZmNO9lNI1P2K8fDiGXQIDS4gG+ tAR6s549kkSKNO3yMl910bnNyO5+fyuL1IqmiuI6I0BLVyArWKNGcvHVgDY15Cwj0umf sCY3IVFJoJpa+OwGbRD99tTIOfD/fNrINoP2IHkxrt87ydvtICcZbkaU+PYyub5vQ6he HBsPXu7tnCq8qJmy3QA0y1WxuwWNzfiAmrdaCggcljLX8NJUrNJ626Uk/nkFj7cN7zRF l6pv3RcO+fpUeXuU1gn4RQkr0ufA8fYLVPgEvHzoFFktM2JU70vDOjfUDjuk2QtCjHQb 5rSA== 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=XpDvqkNxaXQaSUCD2eX0/8eJ4jzHVK4GC4Jj0xDM02w=; b=MHspuNscK2xF5JMj6sxZowxdMzS4yfASLO8v438upFYc2OWyCyHftu18ZpUklFihVn rPkwcPyPAxtfoqxrKU6ZTSVto3T+oW60CFTFpg5SHXgUYjG3vU+91uTT9wkIv5R5iIc1 cezwAVQbCraN8YP7bZDyKl/9qR1NXvsodiyGdxFBxffFVxZazYEGa4su3tWEbjeb37eu pFzk739TqHAvjrEu6SAfzDQW5xMKeEjUinc1qSwmoiIEJs5J6rBv1TOhH+PNjhiCUCrp mI9eSc5/jkajmmXKKgk5vBoTB3vBL/Cq39mZFJK5F0j9kK6ilGOgioiNhTbGgUG0FCwB v7ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=k6jIPqgn; 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 32-v6si26385907pla.348.2018.05.09.11.59.11; Wed, 09 May 2018 11:59:28 -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=k6jIPqgn; 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 S964945AbeEIS5g (ORCPT + 99 others); Wed, 9 May 2018 14:57:36 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:46330 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935523AbeEIS5f (ORCPT ); Wed, 9 May 2018 14:57:35 -0400 Received: by mail-wr0-f196.google.com with SMTP id a12-v6so5657489wrn.13 for ; Wed, 09 May 2018 11:57:34 -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=XpDvqkNxaXQaSUCD2eX0/8eJ4jzHVK4GC4Jj0xDM02w=; b=k6jIPqgncR1pwGZVX3gpwQqk8piXYDuZofD2244oKiaX6rPs0ELwaA8oct1wbM/Vte 6iCiED7rla3xZpzgnupRARsx/YBBwTZsUQ5lNDG8bgwBj1VZakp5qQn4BRl4Mayr4Upx YuX2Ff5Jn5Ca+/+JJROtTtO2gAzkitmH87H2F935RiSuEg1YOemsa4gfSFgoBS/MGuKI wWOfGN/Ku359De/6sfU67aJ4GHXKKAs7Vaxq12I+fjvT4aYXKXFD4J8Z/shiitIAb2wH 5IodiF11aky4RWqvIlpzWyvT0hC0lrFJh+R4KJxbt8aWnxJ7/1+DnTpsQhR5cIiTYII9 T1dA== 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=XpDvqkNxaXQaSUCD2eX0/8eJ4jzHVK4GC4Jj0xDM02w=; b=tg9sO0rf4lsmbR+ZXKJ4TvuK7sMm0RLvOtojQcEksJpuKxAbREKZhiuS1yCInTL7V+ CRCysHsf4Jms6YVG/w19BoBpKtfV89JPW+QpnaAcXuyoWqtbGNacXUl77RxbOSyn0lmX UK7cFoufiz/biujXRsa39/NPM7hZtFfbPs4zdhRm+1keh9zh14NJWSEuD6NWBQeGHE4M 5kAPkW3ajuPLn4Dop2LUxzeX0kDiECjUKmbN8mjkTMTfFaDEOxYqw+JreIk3TvvI2kuG EkxlsanlnuHeuGSNh7o7mrxfaG5EBjWnBgHDf9bLbukwmpUFGUCPe9ogmpymQH20sXGB tCUg== X-Gm-Message-State: ALQs6tAfm0GsEOamntGgM3zLSGUbDjnCbX1t7ElSUp0vHwYMahYMkt/0 xn1NQu5mLfYjLtMl1qqwCvwe+Xx8 X-Received: by 2002:adf:93e5:: with SMTP id 92-v6mr32086733wrp.230.1525892254213; Wed, 09 May 2018 11:57:34 -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-v6sm20899837wmv.18.2018.05.09.11.57.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 May 2018 11:57:33 -0700 (PDT) Received: by macbookpro.malat.net (Postfix, from userid 1000) id 223D410C04F8; Wed, 9 May 2018 20:57:32 +0200 (CEST) From: Mathieu Malaterre To: Srinivas Kandagatla Cc: Mathieu Malaterre , linux-kernel@vger.kernel.org Subject: [PATCH v2] nvmem: properly handle returned value nvmem_reg_read Date: Wed, 9 May 2018 20:57:24 +0200 Message-Id: <20180509185724.24079-1-malat@debian.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180505202450.26630-1-malat@debian.org> References: <20180505202450.26630-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 must be read and error propagated to nvmem_cell_prepare_write_buffer. Silence the following gcc warning (W=1): drivers/nvmem/core.c:1093:9: warning: variable ‘rc’ set but not used [-Wunused-but-set-variable] Signed-off-by: Mathieu Malaterre --- 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..f7b6c85cf393 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(-EINVAL); } /** -- 2.11.0