Received: by 2002:ab2:6f44:0:b0:1fd:c486:4f03 with SMTP id l4csp199706lqq; Wed, 12 Jun 2024 23:38:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXPiQTJNF+s9mIo8MrCZPl4ESiyA/mhutKYHhIqM9eSLZn2nTkW+njWfB8vUjX+X4dbBZMrYqj7z9fM9zEa4y7Eo/uqPHlrpKdsiL5LJg== X-Google-Smtp-Source: AGHT+IE2/9dqn72rWD/XFNovmJjFLEiH96r01NiOsX5fi5J8eAZrw+VloZ7U7kOzSMsbmQbE6f1b X-Received: by 2002:a05:6a20:258b:b0:1b8:4619:eb80 with SMTP id adf61e73a8af0-1b8ab6675c0mr4455876637.62.1718260692502; Wed, 12 Jun 2024 23:38:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718260692; cv=pass; d=google.com; s=arc-20160816; b=ltwXkk7QBROM/RMo9ecAxNKmuU0aE9onIXcgxV7HnWMTtH2ZrxO6ERiNGirj/VUBYO nckMbf55AtbqXOMlsAFJXT4vgNCXFcStZradB4joKqxaoKXgoBajkeUFB5TQehK+nSDQ fr3ewAmMmmnhU+0bdmEltzklvxvUc9v+OkFdHglUFwXkMvEJsx1KUptGMeHs1Om9qRCD DqM3fHOevZwvtS0xJz9IlfLqmPT8cegWFbkK/Cgmm1hAwymxtAeaGhbYxMp65cfIsLjC qi7I4qPPRQCPAV1V2wd/DaAHhikKdujIceEvz/rC2JvU2sXRK6kUu5o0rCOF4uqyfMY+ m+jQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=nSxaLeoUF2GB1Ynl8GPq9r0Ie6ml6kc6+0f2KJsgPRI=; fh=wUZ8x1fulYB0NV0H5gE8lX0ub83VFp87NmaxsdAT+eM=; b=APmo1RlrkbH9lzdVTBnSu6aA7WkWXrPmkIR+YrOqU6kmoLJTUYLC5JcHMJdbe6D8XA uJRs/s32xvP5bm3y4coLnAlhX3eA3Uu7l/lWzBdb/t8e7BUwhpWLz6sU9KSVzZMx5Gx+ fhRi80uH04iMvIyU+Dn0cDRgco5EzsP+lA6Q8xOqZLMokYbmsecxtdaeAajwaHTExE1z AGGlAqGEACd/czfs2lFQ6hXL1CsRBxrd8kXMi/vQ44iIDWBU+dSX2M6CEhbfzdeZEx7r zACYR+PQ7rU+sNRS/uebZYThF+4MUmob3kxjLKfTaN87bOTUemPxaoPmY8K3Ck19aKdv iAqg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="AXEuLiE/"; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-212640-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212640-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f855ee192esi6761075ad.365.2024.06.12.23.38.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 23:38:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212640-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="AXEuLiE/"; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-212640-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212640-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1B1D4282B83 for ; Thu, 13 Jun 2024 06:38:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B374D137914; Thu, 13 Jun 2024 06:38:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="AXEuLiE/" Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38364137761 for ; Thu, 13 Jun 2024 06:38:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718260683; cv=none; b=Xvw6QOK0hRdaB5puknuAb69Oqrn75xwI6521AexZA0a6jNZ47LGWuSIt53dqUFksgn5n4xgpK45FAjav1nvJwLWeCqvS+enIvkTfi63yjHXa31/y51hVuUbnkdEgoAoQTCJsi3b+wdrhoMbkpKqs38yDh/iGi2TjZDITUojFZVc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718260683; c=relaxed/simple; bh=D4H9WEaybswir/ij5ZUvHUvZ3BrEX8LaPweXhA6txCQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=tFIpw5vm16mcwMOnx71KVs4uPggZ8nNNqyCmiChtHurLwdxxEBaEYrk599HajvEW5B8HetvtLrtPHPPt/P3l5HQVnCVbEE9mgGh+uchM3ChmBwro/aAZzDF+DJH54/IHSwKcXQuCirA+1Ar3JUeMKghDb1jNYiPc79XOJ8OKuw4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=AXEuLiE/; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a6efe62f583so59914466b.3 for ; Wed, 12 Jun 2024 23:38:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718260680; x=1718865480; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=nSxaLeoUF2GB1Ynl8GPq9r0Ie6ml6kc6+0f2KJsgPRI=; b=AXEuLiE/uoqR6/G8TRtZ7Fthaw3ew+CCyLh8U8snXL54+PPjXidFKllyGOk7zlkgZv Haxg+yCqc3teH9EoVzDJ4UO8uo0NqPtiml+p7ejaZwi4HfAXFWlCUwXIk38Ff/bbbQfe 8Lvi91ngAvc941Ec8M2eHQGb0wQPivU7s1rT/uXMbXeGDoJk4QMiYWynOk5bsCUHedrK RSD2ANuTVd8505LC25cyLVVKv65xOKW9GFm+sQ5J8TNsSHV97HZOyziPVx8CqjDAMvg2 zrbzDWCRuFDRaYKR47rbc20qvsC22ZAfdWsGEDYZHzyy1RVo3fTtOPcdjoH74/IsGHkq 9LWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718260680; x=1718865480; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nSxaLeoUF2GB1Ynl8GPq9r0Ie6ml6kc6+0f2KJsgPRI=; b=orVEyijL0i62ZRWtqdAr586yURzg1Fd+ccv1fV5ThUrWj9VqR3iSw0etMjmsqiuXq9 Oto8ZNPHfG6M7Tff6iRrvGkn7hfaKOOYwAhFF7TlVcW6HN6DE1KKBC2PDxunvyfpwqPu n7JFmECgrwM/Imwq2/CIMxDNHNA77MiazQ23+WF5gG2uYY65JO90RIN55nTJEqJLrNmb CNu3QE7ZEHpEeDdeovDzPIsOShyIrReBwJ7mQB2l5QkTjPARcv8RsaUda2BS1jPnUWXw AJ59pPFNZixtqyM7BmpmcONWuSQMbqzwAIKWbnHfesM6wtRg58oIqMyIuScuFPQsxcte zVDA== X-Forwarded-Encrypted: i=1; AJvYcCUCLL4D6yN9QLRdiVZR0FUEp5SxTd2e0P8MwYcFFMPsRwiHsAwTwodgIdh0/2ndcXl8r5y/amUjpwHoolBP3pDXhU32B154PfrnF9Bt X-Gm-Message-State: AOJu0YynvHOa2WAlvlaLzdR2P/9CHWeFD54qbutlW8lQKK9NZzjBwvyd Ls6sHcabw1CmBjGvb2Op8+oryC4qBBm+6YNTnJtJJZeZDz09Q8N3dDALDjHbZiUOQl160x1NmR+ +a2nPiuCxPLhgu6jBOcHW9bJK4neisadWEzU4 X-Received: by 2002:a17:907:e91:b0:a68:fb0c:b294 with SMTP id a640c23a62f3a-a6f47d622d0mr247392466b.77.1718260680210; Wed, 12 Jun 2024 23:38:00 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240612180554.1328409-1-joychakr@google.com> In-Reply-To: From: Joy Chakraborty Date: Thu, 13 Jun 2024 12:07:46 +0530 Message-ID: Subject: Re: [PATCH] rtc: abx80x: Fix return value of nvmem callback on read To: Dan Carpenter Cc: Sean Anderson , Alexandre Belloni , Srinivas Kandagatla , linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jun 13, 2024 at 11:48=E2=80=AFAM Dan Carpenter wrote: > > On Wed, Jun 12, 2024 at 06:05:54PM +0000, Joy Chakraborty wrote: > > Read callbacks registered with nvmem core expect 0 to be returned on > > success and a negative value to be returned on failure. > > > > abx80x_nvmem_xfer() on read calls i2c_smbus_read_i2c_block_data() which > > returns the number of bytes read on success as per its api description, > > this return value is handled as an error and returned to nvmem even on > > success. > > > > Fix to handle all possible values that would be returned by > > i2c_smbus_read_i2c_block_data(). > > > > Fixes: e90ff8ede777 ("rtc: abx80x: Add nvmem support") > > Cc: stable@vger.kernel.org > > Signed-off-by: Joy Chakraborty > > --- > > drivers/rtc/rtc-abx80x.c | 9 ++++++++- > > 1 file changed, 8 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c > > index fde2b8054c2e..0f5847d1ca2a 100644 > > --- a/drivers/rtc/rtc-abx80x.c > > +++ b/drivers/rtc/rtc-abx80x.c > > @@ -711,9 +711,16 @@ static int abx80x_nvmem_xfer(struct abx80x_priv *p= riv, unsigned int offset, > > else > > ret =3D i2c_smbus_read_i2c_block_data(priv->clien= t, reg, > > len, val); > > - if (ret) > > + if (ret < 0) > > return ret; > > > > + if (!write) { > > + if (ret) > > + len =3D ret; > > + else > > + return -EIO; > > + } > > I guess this is the conservative approach. Ie. Don't break things > which aren't already broken. But I suspect the correct approach is to > say: > > if (ret !=3D len) > return -EIO; > > Ah well. Being conservative is good. It probably doesn't ever happen > in real life so it probably doesn't matter either way. > > I don't really like the if (write) follow by and if (!write)... It > would add more lines, but improve readability if we just duplicate the > code a big: > > if (write) { > ret =3D write(); > if (ret) > return ret; > } else { > ret =3D read(); > if (ret <=3D 0) > return ret ?: -EIO; > len =3D ret; > } > Sure, I'll do this in a follow up patch. Thanks Joy > regards, > dan carpenter >