Received: by 10.192.165.148 with SMTP id m20csp1502935imm; Thu, 10 May 2018 11:43:14 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqqAV0LfeX/rO8OWoeZ/zYP+gJNEjRAZTM/t2VkadfLQwN6QBTKfF4tLz+rB0LoABAF4owR X-Received: by 2002:a17:902:4545:: with SMTP id m63-v6mr2439150pld.268.1525977794414; Thu, 10 May 2018 11:43:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525977794; cv=none; d=google.com; s=arc-20160816; b=nYyVX/mMKxwaZLRx9W26lOCmv9ElEgFc77faxeulEU7IwTkRaUTzRbYUKqXG1Mdom8 ftR5LdJNHj83od2xDwX70sp2I2vZMxgEbCJBonBv1F+VVQ8Z+sHKef7lPQHlsq1KdOmV KkdMRCumlQeUuugVSNiUg+DKNnudNJ7dPlSwRILqoe9O3Stinf7uRc9GgiDxQlHylgqU 2JqwAoLwnzgRfpCP3n44TkedqakzKJDVlMXXopB6bYVnzqEpnceBWD5oaZTD9xvK87lR ypUcIEx7ORmpgN/y1QS3kiFyloPSv2pD7Cq3tA4aZ2FVvpOJhSLP+LAgsUKwwJyzkruV 2/ig== 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=c8sYTDiUbeU5XpKWWDbdCHjn57YhXIPuZrcO8lWDrTY=; b=hCnwbZkdQTcg0BlKMJZSIuEQQHiCdwXwXOBEy43DnwtOoytUcNXlAM2BWueE7/dqDV u2ftFZ4cvnFuFa6mxgbmsrf7F0Xmu3B4oaXZ1Gm6v/6IMX6VfjOhRfnK6zwW9iPPsmtg 5WTTBO7p/RiOT21wOORIlHeclqKuhyZ9JzpN6hIfRvbZDAgIALfijDKDchx3FflpeNfB oVDfyhMVVzkuup8bgWpiNoFOfgAgrrYcragxVncxORNj8y4jqqxy7t3JhsccHkLIyfYD g2EQ7uGRzzOX5MlitV+3C+eXgHSBJYWqXYR2QWBhqHbVQ5JUVH4u0tJhBDZOign66jZ0 5CWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=hKfYlIep; 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 s204-v6si1137748pgs.164.2018.05.10.11.42.59; Thu, 10 May 2018 11:43:14 -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=hKfYlIep; 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 S1751258AbeEJSlL (ORCPT + 99 others); Thu, 10 May 2018 14:41:11 -0400 Received: from mail-ot0-f193.google.com ([74.125.82.193]:37385 "EHLO mail-ot0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750762AbeEJSlK (ORCPT ); Thu, 10 May 2018 14:41:10 -0400 Received: by mail-ot0-f193.google.com with SMTP id 77-v6so3436839otd.4 for ; Thu, 10 May 2018 11:41:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-transfer-encoding; bh=c8sYTDiUbeU5XpKWWDbdCHjn57YhXIPuZrcO8lWDrTY=; b=hKfYlIepImjDY460Tf8PKRI0imw3WtYwBGE502oE1w8y1eojFs0qRz7AO/v3e5fSpb P/Jzd0IWf+8GbcvbKvis9XesRPiBD5H1PE04++hWrwnwqZb+63JeA19x/y79y8egZq3g jPmCd54sSFk89zgAAChGnG5lbp0a/0TRVTn/fv7Kq5CrSMvRxYAVSDElN0CT65AtqrLm cTRzz3AlYsJE5lO+NNnEi0vc+GiQn5Ib4XPGAl7oekRuiYfYlkKbHHTSjn3vKbnN6mU9 bxqeZvi/aJgYBjWz8pM6f740ZYuHj2LcltRxn7xqX2+pzKuenr42WD0XOMWvV0iM5vGp w+PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc:content-transfer-encoding; bh=c8sYTDiUbeU5XpKWWDbdCHjn57YhXIPuZrcO8lWDrTY=; b=gNqBbWkN+o6MYluNIhKsJS6mhE6OGL1mbrvVrGS/EZK2T5h/F+9jvdXRxtS+i4Ty78 uMF1cLBw9GXGbXDzaprPvj9+bZzpOixdUqu0PXk2YntAWso8TjzSP6dV2EOGlAM5lu23 DFcPpQfwXlXv50qMFVrRqW+S7d5E4Wge9wQbrSGHmb4fbjaRwOwqCrrD3N6ef1jIAfST ZovCGXdCZEagYeE7avkKAMAjeurQ/qtIFxTIYvkQCZJJ1tbCPDUH5SdypPEkNODcAbpO 2bsJG4w+yMsb7A1ggxQ4iuSIlJ2bRC6R5HcgM/dIUc1OIDmU+CyTFnrWExIEkfxiHo1n WzyQ== X-Gm-Message-State: ALKqPweFEX/4DuPP3Ua/PV+rv8fLvQXuiwjxWBI6togVBaV+23EYiFsh GCf8ROqc2Ds+MDJIJU1PKgHBLSQRFI5zMQULi9E= X-Received: by 2002:a9d:1b6d:: with SMTP id l100-v6mr1761025otl.127.1525977669668; Thu, 10 May 2018 11:41:09 -0700 (PDT) MIME-Version: 1.0 Received: by 10.138.3.5 with HTTP; Thu, 10 May 2018 11:40:49 -0700 (PDT) In-Reply-To: <2cb62de4-f8be-e3cf-f415-54de60bb669e@linaro.org> References: <20180505202450.26630-1-malat@debian.org> <20180509185724.24079-1-malat@debian.org> <2cb62de4-f8be-e3cf-f415-54de60bb669e@linaro.org> From: Mathieu Malaterre Date: Thu, 10 May 2018 20:40:49 +0200 X-Google-Sender-Auth: RkKPLrwKSvpgxOLBNQ9VQ0BC7mI Message-ID: Subject: Re: [PATCH v2] nvmem: properly handle returned value nvmem_reg_read To: Srinivas Kandagatla Cc: LKML 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 Thu, May 10, 2018 at 11:58 AM, Srinivas Kandagatla wrote: > > > On 09/05/18 19:57, 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. Silence the following gcc warning (W=3D= 1): >> >> drivers/nvmem/core.c:1093:9: warning: variable =E2=80=98rc=E2=80=99 s= et 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(struc= t >> 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(struct 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 ERR_PTR(-EINVAL); > > You should return ERR_PTR(rc) not EINVAL here. > errors should always propagate to caller! third time's a charm ? Sorry about this, I was not paying attention. > thanks, > srini >> >> } >> /** >> >