Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1147162lqt; Fri, 7 Jun 2024 09:13:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWlByjcSHE4cYocNdFoVZi8CR8eIGX4U/1UbP4yWjoF9vfg7afPYI4IcNSMbMB8oLSTV4MWV3OXmSJVsPH9oug+MGggSSaF4tlMtnMLiA== X-Google-Smtp-Source: AGHT+IHRBbPYBwXIdk3Ny/3YMnRgqMdCyxSzxE32cu/A3gi0jD3cll+0MuDhHSNDLmjuNIj3C4WW X-Received: by 2002:a50:9eab:0:b0:573:555e:6d89 with SMTP id 4fb4d7f45d1cf-57c508274c6mr1997058a12.1.1717776817114; Fri, 07 Jun 2024 09:13:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717776817; cv=pass; d=google.com; s=arc-20160816; b=H8qmyRh1/j8C2dz+BJ57qsNGV88lBS8uvJffQKnEWo4CxSlUXK+31Z7rZS48mWTuSB 38u8BTjOEiNGMkaDKI9GBSNG92TVfH8y6zDCxoTQqSdoOz5b856YRvO4/54zZHNLJvfl HXJuDWMftRQFqqIFKsCJoHU1VYTAom+tYL8OL1ISwX8mSv47y0NXOy7qO6/4KzAorXUs cDaZgEVm0QVTYX+4OZFwMGxkJEMNmR1i4J5nyYFqvuaX0xpJWDwEr7xBDrCnDhvXXrlo sTRNfOvQrZFvZeBcHcsiU0K4Jjpk0osmo6xASs2GCVRWTTORUfQVIqYsuBlRY5gG7ET2 WjNA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=NJQYxePR0iHdVpyH6KgKy957kewW8MXS1xiZJc94kzM=; fh=k5grgSNdYJDBxItEShEZW0mitjjfNCvPaPreGJrJPmw=; b=XqEb3Gyx/NXyLBufioosGhoibmq7C+KjSkzMIAz4zEGeuI2cUdx3ZrW1JKXAeUoj5t zIITtoMzq4SuUfVFjU7C62rZmLqkF5yJYZ3QkHizadjRVW8mFmVKTAFIiPBYK2oN2kEr P39fl21fI/8fDOOmDQl60+KP4C3TGevMz9NUZN3zbYK5MrWh18gbyZsAa9z/tYx7qc5J JYcPoWjZFyid2CrdOFKrhV4zQAgTmt9WZl6M808yuRGD+jfJWTWW8H4uX+zxiomy/dgn u2N6/SQlb6araPWrrFF8iaXfaKslJf0nA9rYYYHWn3uAEy6mazY40m7yUq8yR8ENWOxQ +lxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HKJG1Mml; arc=pass (i=1 spf=pass spfdomain=flex--joychakr.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-206450-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206450-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57aae228e16si2041308a12.395.2024.06.07.09.13.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 09:13:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206450-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HKJG1Mml; arc=pass (i=1 spf=pass spfdomain=flex--joychakr.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-206450-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206450-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4A3441F25F2B for ; Fri, 7 Jun 2024 16:05:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D887199EB9; Fri, 7 Jun 2024 16:05:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HKJG1Mml" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 92DD8199E9A for ; Fri, 7 Jun 2024 16:05:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717776320; cv=none; b=OIGbcKtwfLIHsZ6H1Cw951Zjp1eha7mW+8Ausq8/YJKHrIePZ8OhEu4Ns20/PkQx9Ju+Ncl//e4TEPlTZ7dJBhGTi85aewxZIbxtspaKcVEEAL+4JgN9T0Zz9fZjZF94MDhfVyLF4xz+m9fEIXC8cf1mv76MCWv9jOYBEvVDTqU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717776320; c=relaxed/simple; bh=PkhT36oQfIFSxnsTi/xZYEC1/Wh+3xFYb2O/Bmxgk7U=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=YuyF8280oypuzPUtWE8DhPFA0scqyyq+iMtl/PtgPjBc2GKkxdSf0E9VgNa/VUYHJAph+J0MLRFccpFmlGC3TgVM76rfwDJUJOuovLNPdi/WqFdiLBiddGCMIDrkiR2iMolxnW/WVCOK4poKj8JwIq/QwskD2s186leG1ZU+HSc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--joychakr.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=HKJG1Mml; arc=none smtp.client-ip=209.85.128.201 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=flex--joychakr.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-62a084a0573so38187647b3.2 for ; Fri, 07 Jun 2024 09:05:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717776317; x=1718381117; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=NJQYxePR0iHdVpyH6KgKy957kewW8MXS1xiZJc94kzM=; b=HKJG1MmlycUEQDyL7jY33NzWkNKxhRRLuKxGZXmBpzj6QVrFwDJig+UgEbiI7RWz8L petq5ML37LaxiKkdhHlAX/RQxvhy59E2mzHysH6NpQpwycLZzqhZIl/C7jB4sV+cZr/P 2VznYLlgfoMrcsDdziCW/ZFZWAboSJR/gca3F1SiFG2/NusZ12195zphjErARRWdFFZX /1s7f1elB/agXfYYBzCRLLomEBwjo2VOnJiFJojk6VQY4gXoE3cRVOjNDNCID4pIyJW/ 5d8vUPu5fCTxAUEdVzjqPPBnNR+fN2I20MucDYw0BJD8JUrr1yU2/3Ui8r13ltYn8oOV m7KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717776317; x=1718381117; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=NJQYxePR0iHdVpyH6KgKy957kewW8MXS1xiZJc94kzM=; b=UWxplar/esMWcW9TwC4fqmAfE2YbK35GCJhVelYp1Sp1pW8pBpV7cWE2XR/SOlfMpA bAoZIYVOdqlH2ezDx8nsj5TYicqMic/mrGC46XpFdKEfqbOUFWSl1MxcYgc55MOPdTM6 G5gPOrKk/J9yqeW66h/oZGcDjD3IA3hvCOtJEQicu12iNwNDqypMngcJVZCfOksWQPEG dCDnADuA/4c6oj96mKJJu8KMnKCkxYs9oB6xNbvrutLZsmtruuHYBDbhkpO2vLLBJV5e SPbIW2/GhjkJEv1rF6a5tjdA9VSm2LuNuZKVK9zBh8DLLqGI7nepah5w4BlBW0/esFij VKJg== X-Gm-Message-State: AOJu0Ywp4QeNezAWP/l2J7nreGL20PAXMtMOK+rU6hU4wNqFAWvNC4T1 Nt2sUm9rG2cMlburzDWSF5Y36/9eNSg1N6yAk7Txob7wNzP/vC3F2vy5H+rGHq1adCx+smsXFy5 jxAUYvXiR9g== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a05:690c:6410:b0:62c:c56c:94c3 with SMTP id 00721157ae682-62cd546f5e8mr7536837b3.0.1717776317494; Fri, 07 Jun 2024 09:05:17 -0700 (PDT) Date: Fri, 7 Jun 2024 16:05:10 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.45.2.505.gda0bf45e8d-goog Message-ID: <20240607160510.3968596-1-joychakr@google.com> Subject: [PATCH v3] nvmem: rmem: Fix return value of rmem_read() From: Joy Chakraborty To: Srinivas Kandagatla , Greg Kroah-Hartman , Rob Herring , Nicolas Saenz Julienne , Dan Carpenter Cc: linux-kernel@vger.kernel.org, manugautam@google.com, Joy Chakraborty , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" reg_read() callback registered with nvmem core expects 0 on success and a negative value on error but rmem_read() returns the number of bytes read which is treated as an error at the nvmem core. This does not break when rmem is accessed using sysfs via bin_attr_nvmem_read()/write() but causes an error when accessed from places like nvmem_access_with_keepouts(), etc. Change to return 0 on success and error in case memory_read_from_buffer() returns an error or -EIO if bytes read do not match what was requested. Fixes: 5a3fa75a4d9c ("nvmem: Add driver to expose reserved memory as nvmem") Cc: stable@vger.kernel.org Signed-off-by: Joy Chakraborty --- drivers/nvmem/rmem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/rmem.c b/drivers/nvmem/rmem.c index 752d0bf4445e..7f907c5a445e 100644 --- a/drivers/nvmem/rmem.c +++ b/drivers/nvmem/rmem.c @@ -46,7 +46,10 @@ static int rmem_read(void *context, unsigned int offset, memunmap(addr); - return count; + if (count < 0) + return count; + + return count == bytes ? 0 : -EIO; } static int rmem_probe(struct platform_device *pdev) -- 2.45.2.505.gda0bf45e8d-goog