From nobody Thu Dec 18 00:45:39 2025 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0FF0158D83 for ; Wed, 24 Jul 2024 13:57:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721829439; cv=none; b=MxdUZDrqOS07zaE1Xncx/3iUsa1Q3JVm/wZuoCPqzrPXv3FX7rtKqUtne/9RoNbdRndcJr8W2k/Gn7IHgQ5NYSZNKvPm1NkXj0h6Ri5s20j5N6nrvN4Q/odIv0o1VDEQfs5BFG03qMVnzmFeqHZw/gQFzvM5k4k9slRQjrl1LTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721829439; c=relaxed/simple; bh=oXGrTAaw01JCoGzeWvaK5cjKrKOWX2t0iGTCMPYSPZQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eMioYT8SbW0AAyp3K3UH70kMJNRKuzIid3tqyCXAkD2M9kkUmF4f08b5fkGfb9sfqz9DkpbIWgzXiVOWD4b52XicAYKIv+gRcrc5DlKlU05fLkMbeLW3UwdHsRKlNqWOwNJDS0JqddIa3oz4VvLaPx2Xc6x9XQtO4DE8WGMoic8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=R39da0N5; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="R39da0N5" Received: by mail.gandi.net (Postfix) with ESMTPSA id BC1E220009; Wed, 24 Jul 2024 13:57:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1721829430; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pkOkY2RhTFXAyxMnE6Ar3wQDTX+RRjdEqBlLTafrI9A=; b=R39da0N5OMw0vaR0Fw8Qs2v8lssz28EoU4GL8PDDBgegLUDtdXrfci+hJT6PbkJvwWphjO usWWZSx2b0Gcjm5YtOQbe0FcmM/UpPDteWo6ArttFOv0bE17MkPHQ93lA8H6fIEJ47clsA gPSxlDWRs3CnPfXX5Ir/933kYr5r1TZ/rcJIGXJKqcPyvu2bJ9bAt1gAWbC7Jh0a8ElvpN 3i/COQXZrmucNo/ye9pr++1rgF4jCCgSUfHttkIVEtQi+bdObT6/aqNyFJWBzQawdwgWqJ XaLH1kKMpgM9+BXOC74kI2iChEXZ9F+k37Mk7+1+ORNMhDi88Hc9l2ugXcYE6g== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Wed, 24 Jul 2024 15:57:08 +0200 Subject: [PATCH 1/3] nvmem: specify ->reg_read/reg_write() expected return values Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240724-nvmem-rmem-v1-1-d2e3a97349a0@bootlin.com> References: <20240724-nvmem-rmem-v1-0-d2e3a97349a0@bootlin.com> In-Reply-To: <20240724-nvmem-rmem-v1-0-d2e3a97349a0@bootlin.com> To: Srinivas Kandagatla Cc: linux-kernel@vger.kernel.org, Vladimir Kondratiev , =?utf-8?q?Gr=C3=A9gory_Clement?= , Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.14.0 X-GND-Sasl: theo.lebrun@bootlin.com Both ->reg_read() and ->reg_write() return values are not easy to deduce. Such type of callbacks could return the number of bytes in the success case, which would be translated to errors in the nvmem core. Such mistake has been done in drivers/nvmem/rmem.c: commit 28b008751aa2 ("nvmem: rmem: Fix return value of rmem_read()"). Signed-off-by: Th=C3=A9o Lebrun --- include/linux/nvmem-provider.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 3ebeaa0ded00..515676ebe598 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -92,8 +92,8 @@ struct nvmem_cell_info { * @read_only: Device is read-only. * @root_only: Device is accessibly to root only. * @of_node: If given, this will be used instead of the parent's of_node. - * @reg_read: Callback to read data. - * @reg_write: Callback to write data. + * @reg_read: Callback to read data; return zero if successful. + * @reg_write: Callback to write data; return zero if successful. * @size: Device size. * @word_size: Minimum read/write access granularity. * @stride: Minimum read/write access stride. --=20 2.45.2 From nobody Thu Dec 18 00:45:39 2025 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0FA5158A19 for ; Wed, 24 Jul 2024 13:57:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721829441; cv=none; b=ond9V6ZPrdvAxpPLlzDYJvIJI4ToC6K32Ks/sE4pcs2pO4POyX0hheEmakVErKtWBSTOlMFIe42//4YDG8UsOvDZ0dJErCA19RDW6dx7vnkg38Cr4LcKuZvoChezGtlUMIPxe/f93pQ978gLhRpWbSx7F3//aIa88cLHvdVzJtQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721829441; c=relaxed/simple; bh=SCLNff6uXb7/3wrdyKO3f/bKrvDhO9JvduRpC1kRCSc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=L38ptskPf7CnwW7iP5xOxuU5gi2PReO/iSU5zPBax/LtLJ/Kefu0QIHrMazNTZTNEoNHWrkmMhv2IIpWUeS6VvcQHtsQfCeNohUcvywBJrcFlUPpswwd02Hf3LtW9pKxAbfhcIl9/K2TRtm3y3K2LlLZyctZc5P0Uc+HnqGlzlY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Njwdyesu; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Njwdyesu" Received: by mail.gandi.net (Postfix) with ESMTPSA id 23B4620008; Wed, 24 Jul 2024 13:57:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1721829430; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ygdmJeHBtKUEIRBzNdm/VrVb86KhwUfxux4SNqiARGg=; b=NjwdyesugsN0j9zpdhh0TemeulT7V6aLoopT0O0YObjsX/R5rmLH6qkD+jCdV/SAM11d+O 0bVb1upf4WRdfBvWv5v4cPIwBOuImZP7tyT64jO2LGhT6EcsaRAmYQtCI2hxV7NmxxQK/P UY+snO07lTOZ0sj4PFPcORRIX1TUJWWZHcIbdmaBlwwKlupitSglijnA0GPHEDMFj3aMC5 Val9zZjdfPofXyNEKmpYCcsUCq6mOU/F26oqJhxddhnS9KaspTKJ6pIFTj/tWMzMW8Ez4D L75pLxV2hTnQ+PCJ7avBN8sh4otNh7ZI1i4k9Lujw3cQqTMpNhcIKnQl3OrCwA== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Wed, 24 Jul 2024 15:57:09 +0200 Subject: [PATCH 2/3] nvmem: rmem: make ->reg_read() straight forward Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240724-nvmem-rmem-v1-2-d2e3a97349a0@bootlin.com> References: <20240724-nvmem-rmem-v1-0-d2e3a97349a0@bootlin.com> In-Reply-To: <20240724-nvmem-rmem-v1-0-d2e3a97349a0@bootlin.com> To: Srinivas Kandagatla Cc: linux-kernel@vger.kernel.org, Vladimir Kondratiev , =?utf-8?q?Gr=C3=A9gory_Clement?= , Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.14.0 X-GND-Sasl: theo.lebrun@bootlin.com memory_read_from_buffer() is a weird choice; it: - is made for iteration with ppos a position pointer. - does futile error checking in our case. - does NOT ensure we read exactly N bytes. Replace it by: - (1) A check that (offset + bytes) lands inside the region and, - (2) a plain memcpy(). Signed-off-by: Th=C3=A9o Lebrun --- drivers/nvmem/rmem.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/nvmem/rmem.c b/drivers/nvmem/rmem.c index 7f907c5a445e..b2dd25acd7d5 100644 --- a/drivers/nvmem/rmem.c +++ b/drivers/nvmem/rmem.c @@ -21,10 +21,10 @@ static int rmem_read(void *context, unsigned int offset, void *val, size_t bytes) { struct rmem *priv =3D context; - size_t available =3D priv->mem->size; - loff_t off =3D offset; void *addr; - int count; + + if ((phys_addr_t)offset + bytes > priv->mem->size) + return -EINVAL; =20 /* * Only map the reserved memory at this point to avoid potential rogue @@ -36,20 +36,17 @@ static int rmem_read(void *context, unsigned int offset, * An alternative would be setting the memory as RO, set_memory_ro(), * but as of Dec 2020 this isn't possible on arm64. */ - addr =3D memremap(priv->mem->base, available, MEMREMAP_WB); + addr =3D memremap(priv->mem->base, priv->mem->size, MEMREMAP_WB); if (!addr) { dev_err(priv->dev, "Failed to remap memory region\n"); return -ENOMEM; } =20 - count =3D memory_read_from_buffer(val, bytes, &off, addr, available); + memcpy(val, addr + offset, bytes); =20 memunmap(addr); =20 - if (count < 0) - return count; - - return count =3D=3D bytes ? 0 : -EIO; + return 0; } =20 static int rmem_probe(struct platform_device *pdev) --=20 2.45.2 From nobody Thu Dec 18 00:45:39 2025 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F5D7158DA3 for ; Wed, 24 Jul 2024 13:57:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721829441; cv=none; b=BqoAkiSUqlC4xREsqjfFZ3JdsXcAqx+w5BMmpIKQcUHNnbCK14Ar1KTABXBF2k/GjPnoWJ/L97ZpvJ7z/eJAQtUQfsRBYNlu/bpyeENfDc0ARDoTTzGCxAhw1GrxcEl2WQMo6j/vhoZTG4IMqcjxUaziicJu6nWo5+E6XcUQdyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721829441; c=relaxed/simple; bh=ZaJdQt0D9mYBt/7a7QwTMkE+wN+62KNmLBYo0UShddA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EZQg85WER1PzqVmasaBy99CBvcjScyi16EWpeGcCbDozgaHnV6I4J+Mzu6PEQh8qrDdZ+mM6Xy0dKxZJCuxT+qO4xHUQXwF4o1rsXxSx5Awfl6cnpKn8TP7eJ0NtJgVh+xURue7+pgJt5HgSlvCamDY11nZcsH73O9DIe1ApBEM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=kS/6BaGD; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="kS/6BaGD" Received: by mail.gandi.net (Postfix) with ESMTPSA id 8667F2000D; Wed, 24 Jul 2024 13:57:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1721829430; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QR06apVRJjhxG+CqyyWgjhXKf9amybU00BGsGyyilaw=; b=kS/6BaGDp9r9yAW7MUuyMCYfuCroXo4j4lvgJcNkgPrtzVMiPGmaMJ18IUFt9w07vOwYra dkMsmlO+RJRjsuzDPpwqtCnuomeHiYNUarotrf8WPZ5GcXvUr6dlzPj3fHt86aYXgu6nnY O/crtsP/1ztXujMG4OLwZ9kdkYJ1JOYFDwPAiy8/XBdyjEDd/M4hcqEC+pKyiLQavSeYar 58XJmyGrKgzRUn1/ZjeyLEUifRBnjunJtjhhCFgwuSVJ4l86xF7Aqjd010JfK7DyCfO04C Gc6u2tBk0EDggStNRO9IR8jCBbUTF9llXykATSTuAqakCCpjDXL6BX7T2WVZMw== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Wed, 24 Jul 2024 15:57:10 +0200 Subject: [PATCH 3/3] nvmem: rmem: remove unused .size field Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240724-nvmem-rmem-v1-3-d2e3a97349a0@bootlin.com> References: <20240724-nvmem-rmem-v1-0-d2e3a97349a0@bootlin.com> In-Reply-To: <20240724-nvmem-rmem-v1-0-d2e3a97349a0@bootlin.com> To: Srinivas Kandagatla Cc: linux-kernel@vger.kernel.org, Vladimir Kondratiev , =?utf-8?q?Gr=C3=A9gory_Clement?= , Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.14.0 X-GND-Sasl: theo.lebrun@bootlin.com The private structure used by rmem contains a `size` field that is unused. Remove it. Signed-off-by: Th=C3=A9o Lebrun --- drivers/nvmem/rmem.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/nvmem/rmem.c b/drivers/nvmem/rmem.c index b2dd25acd7d5..418c10cf1266 100644 --- a/drivers/nvmem/rmem.c +++ b/drivers/nvmem/rmem.c @@ -13,8 +13,6 @@ struct rmem { struct device *dev; struct nvmem_device *nvmem; struct reserved_mem *mem; - - phys_addr_t size; }; =20 static int rmem_read(void *context, unsigned int offset, --=20 2.45.2