From patchwork Tue Feb 6 14:37:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Schneider-Pargmann X-Patchwork-Id: 13547384 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DDB99C4828D for ; Tue, 6 Feb 2024 14:38:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1BitiYkfmJ0J99oSBAU6D+i3mgb4GjSHrP6m1fpuook=; b=pOekFpk1kxgTAG BU9RnHKcn/5RuC7HCHtZUMbi4gfpcZx9BO4bCHUucDUO7VhHZWExVDQcuX5mg1mznHwKVOflAuF8R dNQkCTKVHUvPsAIdY0xzg5IYdmFSyIFjZsFpN+Iyu8kwgddHK1rwek6mBBvpIEuK54X2+EUtBaU/O CNJPlymRKxFzL7q5/iYcSVpYtmN4Re2dnmnsujOM0ps7dVAuOrcaM2gdScFUF2tvrPtG5IjSTsQ9M pSGd0qU0dPpZUzuAGyRLeqFieLtL3aukNED5vF3lHG5oaAD7QIZmnlU98pGjDCcRD5aVKK29qehX+ QYomJ3F3bPRPktzCJrxg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXMaK-00000007tI4-2zyI; Tue, 06 Feb 2024 14:38:04 +0000 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rXMaG-00000007tG4-3tsp for linux-arm-kernel@lists.infradead.org; Tue, 06 Feb 2024 14:38:02 +0000 Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-a3850ce741bso10968966b.3 for ; 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=lists.infradead.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=iLhT8xxsyERJ34LDGwC6zJbXaRHb+R8C9HBytsy3/kgidS0CJc9F7n8Fxkpv5Gpnrg PH8XsDAoMuMF8lX59jPClgQrvPB5SA95bo5J1M4SIDff/W3jn1mU3p2h8EREoJGdsvAn TjJFq7qW4aSygrQfEC/uatsyccqKNOGy7/ZksX0QwlnLbrS6yk8NdQwAjpEng5o7D2Ps P+cKiQivJFrYKlLBL0QOgBA+L8ZLAF8uShlafVOgDzN2HnNvmDC37ZQCI8MjNOqL0+so fePSxFzFEUu7ifi7sL944k2klxc+sv9BKVQPnBUJM2+0O8O0VRiC48O29eetJQrDdomg 7vvg== 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=JANLS19H4s5URh2em/HIMTaN/gJJrMdI5jrWV4gWfu83tZMHOlBgzkDNrr32UHPJrW eaGfKqyyOms2XQaPnztDkIu9Sy/trilbe2ctJajEyw02PFsvicx+2zUVviKP3vZUsujd hjUorql4hjry3rmw7x8htS8DTeKPqIafPydcAyX1JTKOH2blPZr5j42zX1UBxkOYzZYT KiJjWoFEy+MoSx3aApMbLnF1WHKCI70huGcy/qdVD54ezWywwrpl2alRGAxD5cY0AHU3 eq4IzrY+Wwp9nkMV3PXtLSX3//kVg9eFOyfF8XsZW6mRLZ5d8nWDDg3p1CjJiIllWIvT kE9A== X-Gm-Message-State: AOJu0YyuSyxuV7o+lw5PDOaOzA9TCOJOq89qMDRdSpJ61M328yZJM2AB rjsn9YrRIyivEybj97Osc8r0FSu9Wm5efy952pVLHuswxVDkrKqU7Vh+axvGc3U7HNnKyMfTSgY N X-Google-Smtp-Source: AGHT+IGfDZNzDhZuGgrHFiDW0n00Aay00UsysXT9f8og4QdjPZfVrVGEK3zbMvScDpk7GfwUUzj0kw== 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 To: Nishanth Menon , Vignesh Raghavendra , Tero Kristo , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Srinivas Kandagatla , Santosh Shilimkar Cc: Andrew Davis , linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Markus Schneider-Pargmann 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240206_063800_992086_264A52C1 X-CRM114-Status: GOOD ( 14.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- 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); } - memcpy(val, buf, count); + memcpy(val, buf, len); kfree(buf); nvmem_cell_put(cell);