Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2948008rdb; Tue, 6 Feb 2024 02:38:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IH0DZZ2QLgwb5MxC2F80GmUlVsf6olnP3HIte/qMkwwOv/gcWkkZ9J22bwJoZKg6KF2ifk/ X-Received: by 2002:a17:902:e80b:b0:1d9:c8bd:3c18 with SMTP id u11-20020a170902e80b00b001d9c8bd3c18mr1199977plg.54.1707215918452; Tue, 06 Feb 2024 02:38:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707215918; cv=pass; d=google.com; s=arc-20160816; b=ToI8aSGjgWZ62uvVt/dYQVYO8PFmIZnhSSBidTAI4k/yBkXltl3l6IZCCU7jsWblAg oDx1Vc/IMICQ10kieMaxq7vrCHOYlX/jWsHZ+AU0vWtR3GVJ9PhfFTK3Fk+YNYw3awxF qS8tC/fhuj1a2Vf6H6gZzrMoNje2z+qMp9TgYk4GlUk8Mkt5TB9p7FAYIXtYW6Ia3Z3Z iRW7/ZauaC1a5l5cMH7S0WGd+STKPepNhxAvWqMKz3pcbDEyVWoFsL8OWrOTkjOFztUH 1d8Ca+LGXG1JgUAJq0HjgxvvIqZ+izrC85TNdlyYwuo3pysohbrEvTw0jS2bsvLZDExb k6aw== 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=UyJeOO1MPwusvT1qEwWipYJ8Xhu38so/v3dEFLAabcU=; fh=dVgx777BdV9HAuOzKms70FGu3bKsKPyvAN+uMeGBLJo=; b=d1E7ikqVVE5TCsNusXt9zpEw+J2fTPSL19hjXY19Vo8RnhalQ+BJ9kM5HjS4+0yEp1 7peGJo2BSHBjyFopbM02Grj78kYq70z1Nm88gIH2XV6CacY9RjSZyQYduWBcraCKNedh chTvLUuH77t9pR1vfI9srkf7lgct2kn13ab41+0q/lMiteEkWcRi903DerNZ4ikB1cBv Q/V8Q2XYekROwu9EbWPiif1gEY96dv0N/biYFcafNwSHpcGdUe6kup0Ha4zas4j1pdpV Ei8za8ZcVj1/q45mlawEiYD7Wcr8L8O2CY5kug1N2JMTi+pzNIggiuy97Wl3LKwLrJUD cLmA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=m7qGRSAs; 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-54690-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54690-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCX1fpEC6bYl7zWnqUYA9Nnn+XaLBeIdzadectxwPQkqAVfjOGBNAepNOZ1aYTG6kbcb3jrlI1s60PThUV0J5mwbE84EYdt52TRhFtFzEw== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id u8-20020a170902e5c800b001d963d963a9si1483673plf.2.2024.02.06.02.38.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 02:38:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54690-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=m7qGRSAs; 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-54690-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54690-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 6E3D8B25186 for ; Tue, 6 Feb 2024 10:31:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E1CD51EA6E; Tue, 6 Feb 2024 10:31:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="m7qGRSAs" Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (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 692771DDC8 for ; Tue, 6 Feb 2024 10:31:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707215479; cv=none; b=iWJM52nenl5SUosD848CU3IKyKBlhUTZ5ivJePu7TCM4BrMNhKorvG1pyJmnlsZK2hveeBgp3RrfV3ln8yY+IUXJB/cUk1iUGY7zhGHqCrn6HRCS1t8unGF9d21vhPc8Tt3bPJHNts1hcqLgBgp5sblR3ydZt5aYedFSDQRT9Gc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707215479; c=relaxed/simple; bh=sLPxnJl6On4z7dGAfTxIzz69n4+dJ+EJJhrxmcXYPWo=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Pfi1+JxCnLnt/S18D+VUTY+C0FNBxwVhQ6oiSeQtzDwplGtxtIHIg9a04Jmpt4BRKoCag3c0QJ71eexsde6qJePkXJzMTiDi/cTPlJTBnznBUf5ngHmcUuIm+713iYnKVd7WYASQ6lEQ9IoPXgIkvyeNqKtvAPDXfHlovB0CFUQ= 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=m7qGRSAs; arc=none smtp.client-ip=209.85.208.42 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-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-56002e7118dso4283759a12.0 for ; Tue, 06 Feb 2024 02:31:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707215475; x=1707820275; 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=UyJeOO1MPwusvT1qEwWipYJ8Xhu38so/v3dEFLAabcU=; b=m7qGRSAsGprTwYCekIhFbM7L8RoUJqO2Xs+7Qnnln0EZUQIvhrM3OzYG5cmWmVdZNw YBA6oz2ERoOQEnV2kwp+A1v4K1C2d7Na9N20Dlb/RczNDta2wFDg+v20PbjEJPFzc83Y ERDjzmYRdVmoV7feSWzC4lrnbllOdl+Rc0PzdlOa+huEaiaLjOUoP3EZ9DBXSoKFGIJJ ozuO2hNXKV/1XGoUSi1+ty5J/UIRnT8Py8Y8VAOn6E7UKtavXkyYFuuyvsr32wyWvpD/ gwkV4Y1dtIq94U/vJhrBYFQT920WlHKbBXO85xpV5QxWi0cVCteFyGZYNadGpLjVDHF9 J8LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707215475; x=1707820275; 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=UyJeOO1MPwusvT1qEwWipYJ8Xhu38so/v3dEFLAabcU=; b=fWqtvOg6PVUTY/aAd07vDfJmcJZd8iFwgs7jmv1eHeco+9UI2kfyDjFAZSWmCNHykq 2foHlHiMuV2DWilhhNu+dSa2pvicRJReGGsTfp4K337twsRQmHU9Ipww7ThqvKAhLLMw d7J4v9wDtHLaaAxcXmat9VKoHhJRUIbhb8L8LDchykaRVOfSZkzQT+3ObWT5CXjA1ZXy oBLkHfYfoNbGKtHvLsXpdMhMQb9/2xVnKS3Cex9DsaW0fcb2vHcAOPATMhoToDRWSS4y y2w4iMBUntPY7qTjFAtzDld0qvtjx5E3kQBjfTIbcPrRqjyG+si5c6EwQ5zzElA+UcLo j0HQ== X-Gm-Message-State: AOJu0YyvY3upujo2vS9zUQNkIMLT3E93G4BxZQF87gG2xLs8vfoQwcqH 3vgrLDOp9YopXf1+ZFRs92gOMfqgrdvHSTtiKtrODLgYHWbQxFp9E/Ud1wL8luAjQS6wJxPihzo +F2/JEEVsLAz/blgKUTnIJjyfFO2vRPYLKYum X-Received: by 2002:a17:906:bc94:b0:a37:87e1:5929 with SMTP id lv20-20020a170906bc9400b00a3787e15929mr1592434ejb.54.1707215475447; Tue, 06 Feb 2024 02:31:15 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240206042408.224138-1-joychakr@google.com> <2024020647-submarine-lucid-ea7b@gregkh> In-Reply-To: <2024020647-submarine-lucid-ea7b@gregkh> From: Joy Chakraborty Date: Tue, 6 Feb 2024 16:01:02 +0530 Message-ID: Subject: Re: [PATCH v2] nvmem: rmem: Fix return value of rmem_read() To: Greg Kroah-Hartman Cc: Srinivas Kandagatla , Rob Herring , Nicolas Saenz Julienne , linux-kernel@vger.kernel.org, manugautam@google.com, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Feb 6, 2024 at 3:00=E2=80=AFPM Greg Kroah-Hartman wrote: > > On Tue, Feb 06, 2024 at 04:24:08AM +0000, Joy Chakraborty wrote: > > reg_read() callback registered with nvmem core expects an integer error > > as a return value but rmem_read() returns the number of bytes read, as = a > > result error checks in nvmem core fail even when they shouldn't. > > > > Return 0 on success where number of bytes read match the number of byte= s > > requested and a negative error -EINVAL on all other cases. > > > > Fixes: 5a3fa75a4d9c ("nvmem: Add driver to expose reserved memory as nv= mem") > > Cc: stable@vger.kernel.org > > Signed-off-by: Joy Chakraborty > > --- > > drivers/nvmem/rmem.c | 7 ++++++- > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/nvmem/rmem.c b/drivers/nvmem/rmem.c > > index 752d0bf4445e..a74dfa279ff4 100644 > > --- a/drivers/nvmem/rmem.c > > +++ b/drivers/nvmem/rmem.c > > @@ -46,7 +46,12 @@ static int rmem_read(void *context, unsigned int off= set, > > > > memunmap(addr); > > > > - return count; > > + if (count !=3D bytes) { > > + dev_err(priv->dev, "Failed read memory (%d)\n", count); > > + return -EINVAL; > > Why is a "short read" somehow illegal here? What internal changes need > to be made now that this has changed? In my opinion "short read" should be illegal for cases where if the nvmem core is unable to read the required size of data to fill up a nvmem cell then data returned might have truncated value. No internal changes should be made since the registered reg_read() is called from __nvmem_reg_read() which eventually passes on the error code to nvmem_reg_read() whose return code is already checked and passed to nvmem consumers. Currently rmem driver is incorrectly passing a positive value for success. > > And what will userspace do with this error message in the kernel log? User space currently is not seeing this error for nvmem device/eeprom reads due to the following code at nvmem/core.c in bin_attr_nvmem_read(): " rc =3D nvmem_reg_read(nvmem, pos, buf, count); if (rc) return rc; return count; " since it expects to return the number of bytes. Userspace will see a false error with nvmem cell reads from nvmem_cell_attr_read() in current code, which should be fixed on returning 0 for success. > thanks, > > greg k-h Thanks Joy