Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp3076786rdb; Tue, 6 Feb 2024 06:38:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IEDt8CzM5BPZMrsPbfK7RO5GoAa8RAT4INVpX9jvIwL/07LuxGMWiogrlpSPtgcuGNdFgio X-Received: by 2002:a05:6402:2d0:b0:55f:d9d1:6de1 with SMTP id b16-20020a05640202d000b0055fd9d16de1mr1953911edx.16.1707230317229; Tue, 06 Feb 2024 06:38:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707230317; cv=pass; d=google.com; s=arc-20160816; b=ax7UY25fUFZxwBBrMwECoLY5Ak099BNskLqHyaAIxvU061FEL1RqMbH4U8qW45VUVa YMk1vGG7wkaAaT9vna+asqm/+ojU+6UY7lFmfGS4BWxmmBv9nFqY4XDyC57CvUtS9Qka M0SKaSrZ3FH7r26olcDGeMwuyzecNYtJeR+Bi98i6ggbE8D0C0vNrfnam6Xy0tFOrEqj UqYlXniFoTOn6OYykk8elFArNqjhLj6ejRoZBHPhF+OIwVdYt3jE7LuKaW5d52Rk0TbM jNn+k9RRkm8g67+thDPJjhNcngNMJf10g1IsPfg5zMVtBSBxKqEeP1Vr+4YO01rGSeer ccNA== 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=svx8UgMeB4Q2aJNBJYOSeWETPEJVOcZ40pSO8qu+Sc8=; b=c8X2aXmhtNW8ruzXV9k8MotIj9+xKKN5+26aZvlbxLpITOGAniNAMwJ7kcKnl5yB3/ nPgs2WdNBGQOm+v+3r1coPRGnWpvLQGXaTftYjkfRwQuJL2qZMPbnnUVNyZsGEo40fDl GC6uWE0lNiKMSWmOG7ubyBadL3TLrDjbfFTVSsajvB3BxyMc0JizG9dSlx0m/zAIJkFT j3f6YiRbfG73tOkAC/GBn343cDHwl+/DdO344nCuXjbenNwIxGbxIQoweu8Xh4DmzxBv mHNgGfyFhcJ2HNjCqCTbTJTOF2C1aa3cFYLnsd8X1oG03EhdrpMfi41B0FtEAFLAXOM4 94Cw==; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55127-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVb/I26/oxv5sDAmVI7Zn3XmwFN4HB5nzunDEDaBpU2mf+fJ/VUaPUkxSLX5UkAwTVz1BtV2hgTs9FEH1AvwXuaPtkONaSLjinDv1Qk6g== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id m18-20020a509992000000b0055f49c246f1si1151646edb.624.2024.02.06.06.38.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 06:38:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55127-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55127-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8984E1F22DB9 for ; Tue, 6 Feb 2024 14:38:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A1AAF133292; Tue, 6 Feb 2024 14:38:03 +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 ; 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 ; 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 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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); -- 2.43.0