From patchwork Mon Dec 2 11:22:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sascha Hauer X-Patchwork-Id: 13890299 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 379691FECCF for ; Mon, 2 Dec 2024 11:22:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733138573; cv=none; b=b3YxE5UgAIhQEKdCKzdGEd0PfwjkQ//pR/FUrxNP9+lUb6oSDWWK3Rb5efDe2lVT82aDqwlikkxP2aPAPQM5RfKbOytbzwflNjq/5OTcgOiZwCCqYrZ7jk1xyxf2a/PphHg8ZKeg+xlP1OuSOcWzivvvhOozS3TIlYAbbE0k2ZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733138573; c=relaxed/simple; bh=13U0y1DundmGRi1xvon55DH1ztxxWp3gT5PczadoflU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AhFIvapQ3F7MD2JaPz0yEZUx1jNw9eE+Y7fcD2Mg0U87xpxIMSSoksLr+DAzRyavh0VBR55IX6H48xImcHLCtVSQkDI6MrFhmBSSoPSlz5DN503LzpE1GlCputdOrwRg+7zOYQ50i5b4fqwoqH5ndHA3+TdIIAJM0KeyU3vX0IY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tI4Ve-0000UI-ED; Mon, 02 Dec 2024 12:22:34 +0100 Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tI4Vd-001Ht0-00; Mon, 02 Dec 2024 12:22:33 +0100 Received: from localhost ([::1] helo=dude02.red.stw.pengutronix.de) by dude02.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1tI4Vd-003R1L-2C; Mon, 02 Dec 2024 12:22:33 +0100 From: Sascha Hauer Date: Mon, 02 Dec 2024 12:22:30 +0100 Subject: [PATCH v2 2/4] nvmem: imx-ocotp-ele: fix reading from non zero offset Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241202-imx-ele-ocotp-fixes-v2-2-3c021a97eb5d@pengutronix.de> References: <20241202-imx-ele-ocotp-fixes-v2-0-3c021a97eb5d@pengutronix.de> In-Reply-To: <20241202-imx-ele-ocotp-fixes-v2-0-3c021a97eb5d@pengutronix.de> To: Srinivas Kandagatla , Shawn Guo , Pengutronix Kernel Team , Fabio Estevam , Greg Kroah-Hartman , Peng Fan Cc: imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sascha Hauer , stable X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733138553; l=1630; i=s.hauer@pengutronix.de; s=20230412; h=from:subject:message-id; bh=13U0y1DundmGRi1xvon55DH1ztxxWp3gT5PczadoflU=; b=Aa2jpkZtQUeqa7jmm+aHcdZF/SSMt2EEoIoiHBLUGFZVDzWDKp3Vwr5I1vVqnIhaB7v+q40LY EgGwKihcNr9CFEt2D3C+NDZsbtklxiFYhfvbcamWaivc/F6D8NempLF X-Developer-Key: i=s.hauer@pengutronix.de; a=ed25519; pk=4kuc9ocmECiBJKWxYgqyhtZOHj5AWi7+d0n/UjhkwTg= X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: s.hauer@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: imx@lists.linux.dev In imx_ocotp_reg_read() the offset comes in as bytes and not as words. This means we have to divide offset by 4 to get to the correct word offset. Also the incoming offset might not be word aligned. In order to read from the OCOTP the driver aligns down the previous word boundary and reads from there. This means we have to skip this alignment offset from the temporary buffer when copying the data to the output buffer. Fixes: 22e9e6fcfb504 ("nvmem: imx: support i.MX93 OCOTP") Signed-off-by: Sascha Hauer Cc: stable --- drivers/nvmem/imx-ocotp-ele.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/nvmem/imx-ocotp-ele.c b/drivers/nvmem/imx-ocotp-ele.c index 2e186b7d3b040..b2d21a5f77bc1 100644 --- a/drivers/nvmem/imx-ocotp-ele.c +++ b/drivers/nvmem/imx-ocotp-ele.c @@ -71,12 +71,14 @@ static int imx_ocotp_reg_read(void *context, unsigned int offset, void *val, siz u32 *buf; void *p; int i; + u8 skipbytes; if (offset + bytes > priv->data->size) bytes = priv->data->size - offset; - index = offset; - num_bytes = round_up(bytes, 4); + index = offset >> 2; + skipbytes = offset - (index << 2); + num_bytes = round_up(bytes + skipbytes, 4); count = num_bytes >> 2; p = kzalloc(num_bytes, GFP_KERNEL); @@ -100,7 +102,7 @@ static int imx_ocotp_reg_read(void *context, unsigned int offset, void *val, siz *buf++ = readl_relaxed(reg + (i << 2)); } - memcpy(val, (u8 *)p, bytes); + memcpy(val, ((u8 *)p) + skipbytes, bytes); mutex_unlock(&priv->lock);