Message ID | 20240206143711.2410135-2-msp@baylibre.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-55127-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1605839dyb; Tue, 6 Feb 2024 07:11:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGM6dFF/4fobF99PQ+MyjVv5k5/YF2ZnOuWDHwrtVhdy7sKbtCRt2MShA50EuBxORTo75d6 X-Received: by 2002:aa7:8492:0:b0:6e0:4f30:bcfc with SMTP id u18-20020aa78492000000b006e04f30bcfcmr3911226pfn.9.1707232314069; Tue, 06 Feb 2024 07:11:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707232314; cv=pass; d=google.com; s=arc-20160816; b=T/k6c3y3xzkSynKBx+EOxumKKG7MBF2sSs6Kk7pvIJUbrnon2IcRHKBLc26lqIecPg bfVAPWUOOFW69AIIqEk9HdCKiR+B6mi+g9JNP/tx/ld2Bu7dCh5JhJ2vlSoNEUsGQ8i8 dK3tVyHAMFAP+51sQAX//I47Zdy8MBDPpDnQ6jA6HNJXgQ1jzUZxuCjlZ4i7ZOmzwdJc 08QFvI0CJw+uTptCep1H8Rv6B7KYl/Icl/OUALhgF+pIo9JPc3UtyDPCZjqdhBqaoDJI twM0/j5DrDO/ghymX/vBDQWc68tfBPIRWUHXvSLhmij8005nF40lMhoHL0lYPPwIP1q6 ZB/w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=9NBgzZuNQ3XMEUB9jdo795d+Eu/PODGnrBF33YaDmlo=; fh=d1XqJKdU7js4pcmjSbESlyPAsf7GE+P2G0U8NjLr/s0=; b=Zzl+xZsgeK5BI/R04G4TmTnZJiLcmEGdHyiw6vTXk33gJx5Xv+yKMK8Fxg0TsdccYc 2a5OGyTs2jPMsMSb+qPi39MLF/lWHlOeR6y+1weFfSeRCXhDPmYNBdm0EolfTsWVagrF H8f0V429tCFfJdJ+6Lk9IlsYdbiTkOBkORH08HtZpefV+7Ck8nA2dS//GLRVsItN4XSL Qt+XA/bpTb30Bzzcigi1n6cvoXCm1VjuD3vwQWc+SsuB4N9Hfa8BMkKkqsgo+Dp3GMI0 q5Eg+WU066mjTAdp8gAhq8+IAp8PBpHGM7tzNhVVQOsC5nqnEL2RYg2oMlDl370+Kw20 xiWA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=qsGMkixy; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-55127-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55127-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVaA42bnkrFxIxL4CT1IbiqB6y26dMvwXqLI72jNMuNH4zUWa+/V4/FlhIgmy936SnzWXBQAQJv5dNOQHZiClNOzI3bDQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 30-20020a630b1e000000b005d8fdbbd5d6si1707584pgl.718.2024.02.06.07.11.53 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 07:11:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55127-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=qsGMkixy; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-55127-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55127-ouuuleilei=gmail.com@vger.kernel.org" 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 479A2B2C8E4 for <ouuuleilei@gmail.com>; Tue, 6 Feb 2024 14:39:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB8A3131750; Tue, 6 Feb 2024 14:38:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="qsGMkixy" Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (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 C279E132C24 for <linux-kernel@vger.kernel.org>; Tue, 6 Feb 2024 14:38:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707230282; cv=none; b=IcQe77jAMn1MZx1eryw5yL29Nol7JNWSBzKtjiMaqNuAkZTsGva0TewT6X20M7LKaRicoOeA61wpzjn/25WC9TqKVT1Hrgf3A73iZXmgn5+pjwG8B4pYw55dPEiPnePss28rUtfvwGYRl6GkhIQ8jCCpWGN1GPprsgncMguPyPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707230282; c=relaxed/simple; bh=xtB3eH2nc7TbBl5//VOpSw/2z14pXQ/9Y8lHi5/2iUE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X0hV4n9OHJcOazOdTLVDeBgH07ySpnjBZjiWoHJ3Duw5l8oIrkj20+uDvmBKeBl+UXSMiK54vWsKvYGiwZEoKQGiHzuIArgiimd4NyirTIlJTDXUG6pSPJoUOLH1G8cBZ1esoxClTZnJoFPYcpjzaNvae7Qz2+BkzWuLvQgfu5w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=qsGMkixy; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a380c98e824so124708066b.2 for <linux-kernel@vger.kernel.org>; Tue, 06 Feb 2024 06:38:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707230279; x=1707835079; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9NBgzZuNQ3XMEUB9jdo795d+Eu/PODGnrBF33YaDmlo=; b=qsGMkixyaX0y7ygfx4CsJcsLyjvGJ08Hc88xHf6lCGFLwDfaX/AsFwUNISR/3u1qr0 1wR6f6jeDs3/Ej3xenpls0RmMCJ9uiRNLzCa0Vdm18lWkl2WYNmwvwUZP+RK98+nR1qz pwvBBUruKviPEnWBwM7wnlCIeNKpLxf4ZLy1ELCYkb7jDRcDLbBdaSNNqhFPJvCCABhY fQbPYUdsUrl3FnuWyOKtPeoXSwK2ytcT4wfPjUXJb18BtOP1UHkmbrhj7fH2ZzPknX5C 8aYItpOv3VDhK2yaXaN6AkgFDgXQW8ILbSmPswp4mS/4dNAwrm4WK8JNthjp90Mn6LWH VSVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707230279; x=1707835079; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9NBgzZuNQ3XMEUB9jdo795d+Eu/PODGnrBF33YaDmlo=; b=aKfz2OH4w20BanPh8UN/eshMkCxfCAIA8lbJ0RpP5hhH/2sgpeDu/jCXqXnJ4tts0+ zMR73Zsdmb2P1MJEW7BPkuzr524cjeWVQ/lhCJ3Y2ifF8JlCUHAWZewrnrg3ANGVtelC 0KFE2/I11aSaZ67XJfQLl+mDdmcB6vz2SpB96jExIjmN8jUbFrPY1gJdbDp/3xOpEGgg X6Cw3TXci5vBewh5N/GE0baKRAM0ZMmEt9ph242KoY1ybNZvJ+dg5WNzr/wyUvD7njhA chlLpcywg42l7Ab2ofDN+EfFm+d0sF3hQvRrogURbEjhujA1mhdMtj8AgRXzK9E/ZFNS YRwg== X-Gm-Message-State: AOJu0YziKE5RTJkLdZbLDwn8qj9DRIwjZOVRVBCHfrWSwAiUfUiauVX/ fEmP+rR6FkRIJgKV9S3hk0zSgcvKgYQw4c40NUc+HZRQs2mFuV1XiSoZUbSj/L0= X-Received: by 2002:a17:906:2e8c:b0:a37:b496:f0ab with SMTP id o12-20020a1709062e8c00b00a37b496f0abmr1833327eji.14.1707230278865; Tue, 06 Feb 2024 06:37:58 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXg8CxjHULLVpZPgZYWeojozwzAg92plTJtWd81a+UmkuTg8Qx3/8fQJBUIPRiYarOw0M/r2WrIaR3HQHuAV/Hx4TvqSIXWRy/pfYfrIN1sbHW5GF2QtBQOxtgDV6judqjqkCBjAllXbA43szdyaoJysbOJPfjXmu/SnFPi5IcitGSrbRMco1K4ouSinHqmemKn5L5H4mfA5sZAuu0XdtwwoDa037B7f8MY7GxcJ4aLYu2Fg4R31HygCq9LNxXuIePFzbANj4TJlfaoxKnpQaIxCDkoAuXab0E3XO8/h5i39vD4p5R3Efipux3/xxnfyTf5jmTLiO4EC/stLIqa5dm/H4/llKHxmPXulRSxsOrKhVE5ZhRUtE148PwUnBKN+mi0afsVBkpnZnyzGCMNilcpjeU7TN3I0lD5hPs3HBZpurQUX1iR Received: from blmsp.fritz.box ([2001:4091:a246:821e:6f3b:6b50:4762:8343]) by smtp.gmail.com with ESMTPSA id e22-20020a1709062c1600b00a37585d5dcesm1224418ejh.51.2024.02.06.06.37.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 06:37:58 -0800 (PST) From: Markus Schneider-Pargmann <msp@baylibre.com> To: Nishanth Menon <nm@ti.com>, Vignesh Raghavendra <vigneshr@ti.com>, Tero Kristo <kristo@kernel.org>, Rob Herring <robh+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Conor Dooley <conor+dt@kernel.org>, Srinivas Kandagatla <srinivas.kandagatla@linaro.org>, Santosh Shilimkar <ssantosh@kernel.org> Cc: Andrew Davis <afd@ti.com>, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Markus Schneider-Pargmann <msp@baylibre.com> Subject: [PATCH 1/4] nvmem: core: Read into buffers larger than data Date: Tue, 6 Feb 2024 15:37:08 +0100 Message-ID: <20240206143711.2410135-2-msp@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240206143711.2410135-1-msp@baylibre.com> References: <20240206143711.2410135-1-msp@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790162831115376590 X-GMAIL-MSGID: 1790162831115376590 |
Series |
soc: ti: k3-socinfo: Add support for nvmem cells
|
|
Commit Message
Markus Schneider-Pargmann
Feb. 6, 2024, 2:37 p.m. UTC
The actual size that nvmem is using internally on a specific platform
with a specific devicetree may not be known in the consumer code. The
maximum size may be available at the same time.
Allow the use of larger buffers in nvmem_cell_read_common() by setting
buffers that are too large to zero before copying into them.
Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com>
---
drivers/nvmem/core.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
Comments
On 06/02/2024 14:37, Markus Schneider-Pargmann wrote: > The actual size that nvmem is using internally on a specific platform > with a specific devicetree may not be known in the consumer code. The > maximum size may be available at the same time. > > Allow the use of larger buffers in nvmem_cell_read_common() by setting > buffers that are too large to zero before copying into them. > Can you explain why can we not use nvmem_cell_read() ? there is an other thread to add get_size https://www.spinics.net/lists/kernel/msg5075254.html > Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com> > --- > drivers/nvmem/core.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c > index 980123fb4dde..6fa061ede605 100644 > --- a/drivers/nvmem/core.c > +++ b/drivers/nvmem/core.c > @@ -1806,12 +1806,14 @@ static int nvmem_cell_read_common(struct device *dev, const char *cell_id, > nvmem_cell_put(cell); > return PTR_ERR(buf); > } > - if (len != count) { > + if (len > count) { > kfree(buf); > nvmem_cell_put(cell); > return -EINVAL; > + } else if (len < count) { > + memset(val + len, 0, count - len); no please.. this really does not belong here. --srini > } > - memcpy(val, buf, count); > + memcpy(val, buf, len); > kfree(buf); > nvmem_cell_put(cell); >
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 980123fb4dde..6fa061ede605 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1806,12 +1806,14 @@ static int nvmem_cell_read_common(struct device *dev, const char *cell_id, nvmem_cell_put(cell); return PTR_ERR(buf); } - if (len != count) { + if (len > count) { kfree(buf); nvmem_cell_put(cell); return -EINVAL; + } else if (len < count) { + memset(val + len, 0, count - len); } - memcpy(val, buf, count); + memcpy(val, buf, len); kfree(buf); nvmem_cell_put(cell);