Received: by 10.192.165.148 with SMTP id m20csp2099964imm; Sun, 6 May 2018 06:59:51 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqW0DUuqZj2xVpKhqkrrVYaQAj5LmUzKIOdmAHaSwhQmFORz02TX+gxeGde5NfUA4jCBhhX X-Received: by 2002:a65:5504:: with SMTP id f4-v6mr13160657pgr.177.1525615191915; Sun, 06 May 2018 06:59:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525615191; cv=none; d=google.com; s=arc-20160816; b=Lo+RtuSo7bPrOzmm/9ilWr1ZHo555l4Qv3orKUYuKetu6XS1UDnP72NJGsm4xdPCwg qdjIC5Jgtb7SDppUgHi0tFgBPMOFa6BFOoxa99K/ay6woYYa9X97r8Il5VP6GUA6pSxg vk9aX9XTfJvuactrX2B/F45CmxZ+9B4f/iC12NBlMpn5+MT8rfORfUf0w7VG79tThI/h RRBqRyMYnVDLX94ZgfvWznDk0T9aZvJHy1SUDRYanvMcTGg/AlkMXd8FeVDtVVloC0Dh pRjrhTRKXZ+wS/rmeGbiz+YCoVjg0i2maWnB5hpNJkOYTsuwQUE9xX9CJHQUMhJh02oh wSlw== 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:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=EqShLCPFRtqvtLBbaGhObhbRIjtIN4OKsSfgmheOn/c=; b=xsh1nFMqvNsGsqD3dc1MKZ4P5sujkw0HJT/FPcogE6LVGQNJDfqcV4QVw68j5WpeRW aeXWIJeHcXc9IVlcl0BcaCyyaW2AlBrUVMkpRVp8Lm4ajaKyOOkNw5yOSeOoyofSitlX j5/Cbdlf4CZu1QDgv0A6tiPXcdXQjwE8FTnEEwF+KWzB4p8jaruG6Q9AuBePON9/mQKQ 6/XvuDRK0kgfyhDkUY0f18q3sXMZWczj+FUB5TgybEJ4fqzHEtmTq6UjFHcNqDiBJJ0/ 8+8oq6CRDuqmatERaH+//aMSgitDp0guN+0qusOphFKh6LOgfUSfTz6y37a82NPG2kdR GLSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OnVQ2MLB; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d25-v6si18573383plj.344.2018.05.06.06.59.35; Sun, 06 May 2018 06:59:51 -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=pass header.i=@gmail.com header.s=20161025 header.b=OnVQ2MLB; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751431AbeEFN6K (ORCPT + 99 others); Sun, 6 May 2018 09:58:10 -0400 Received: from mail-qt0-f182.google.com ([209.85.216.182]:44348 "EHLO mail-qt0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751230AbeEFN6J (ORCPT ); Sun, 6 May 2018 09:58:09 -0400 Received: by mail-qt0-f182.google.com with SMTP id d3-v6so33057473qtp.11 for ; Sun, 06 May 2018 06:58:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=EqShLCPFRtqvtLBbaGhObhbRIjtIN4OKsSfgmheOn/c=; b=OnVQ2MLBCAPjY+TK+WiRCZOnkCmWhh2E5Bd01XNnk4FjZYxj/CLK1NxI1SQ3iTVf/G 6igJ4dNaGR1fAQW3sxrs16kw31SzuCI+bPlotf/ZPDXON/RIUODFCa5rX9zNlZfzKkra /F2QahYeeyw7vLc5vTpihVaaKXAReuI+6uuqtlNI5k2fogudDcgazramyqFm8icGwuxl PWCNJDWzKGMsC4L32LSQZaxnE+Ddl3HPKT+TrAFMADV6YKUcMwa1Mwj6m+52YemUQTo2 cRUyWODMPV6CejKUEccT4qgjFcz0M4wAiaiLkxq7bHcvjS0sujBmqTN0oRsTZfxK9ZSl C6eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=EqShLCPFRtqvtLBbaGhObhbRIjtIN4OKsSfgmheOn/c=; b=Zl2SgSrUQcGlFZuECcWK7KlmvFd7562E40dex9acDhHc4qtXIRD3FH6ogoLh+1j2s9 dy0T9pfuYfKBZRpDD6fknzy6lhcSrVNn5FYhc12dqq4TVmqpBAAm2njLssXEXaRQtaBn T84Bf8karVEabyRRDQUYQ7bc9lDQwQcMW0g6rv8KwmrYgt8vUiFDwT8KD0KLTWn7Aw+h MFgOyDuC1j4FSpP6slqb+WOO2DxlbPfKTwNGyHTd6zwCHkRcCvvHj/f2EUSOgz0dDgjb i0gOtROj8PaQAEObJIpZ64bewFGAk1kgruuVVWVUpLKRgiidN/29vgoiwzjFhibm4hRi 5geA== X-Gm-Message-State: ALQs6tCI9L5Mrc1Eo8o1TnxG6hw3RP0btQTOruGEBoiOdKdLGwCZSkmM 3DIVvZgxN1FVh+rHQKHmLAhieQaJ0VaTbAo0epU= X-Received: by 2002:aed:3dcb:: with SMTP id j11-v6mr23907204qtf.404.1525615088581; Sun, 06 May 2018 06:58:08 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.152.150 with HTTP; Sun, 6 May 2018 06:58:08 -0700 (PDT) In-Reply-To: <20180505202450.26630-1-malat@debian.org> References: <20180505202450.26630-1-malat@debian.org> From: Andy Shevchenko Date: Sun, 6 May 2018 16:58:08 +0300 Message-ID: Subject: Re: [PATCH] nvmem: properly handle returned value nvmem_reg_read To: Mathieu Malaterre Cc: Srinivas Kandagatla , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 5, 2018 at 11:24 PM, Mathieu Malaterre wrote= : > 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. Must is to strong word here. How come it *must*? Did you investigate the history of the changes that brought us to current c= ode? How had you tested your change? While it looks subtle it is in one of the storage class devices core, which might be very sensible to changing workflow. > Silence the following gcc warning (W=3D1): > > drivers/nvmem/core.c:1093:9: warning: variable =E2=80=98rc=E2=80=99 set= but not used [-Wunused-but-set-variable] This is least argument to accept this patch. > > Signed-off-by: Mathieu Malaterre > --- > drivers/nvmem/core.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c > index b05aa8e81303..f34f2363925a 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 =3D nvmem_reg_read(nvmem, cell->offset, &v, 1); > + if (rc) > + goto err; > *b++ |=3D GENMASK(bit_offset - 1, 0) & v; > > /* setup rest of the byte if any */ > @@ -1125,11 +1127,16 @@ static void *nvmem_cell_prepare_write_buffer(stru= ct nvmem_cell *cell, > /* setup the last byte with msb bits from nvmem */ > rc =3D nvmem_reg_read(nvmem, > cell->offset + cell->bytes - 1, &v, 1= ); > + if (rc) > + goto err; > *p |=3D GENMASK(7, (nbits + bit_offset) % BITS_PER_BYTE) = & v; > > } > > return buf; > +err: > + kfree(buf); > + return NULL; > } > > /** > -- > 2.11.0 > --=20 With Best Regards, Andy Shevchenko