Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1093209rdb; Wed, 24 Jan 2024 04:53:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGtPY8QeSzBxQuUclpPEJQbNB2/i/SE2GKqdnTO+Y4J1o4MlKE5SHiiJRQQRm5daIKVuKxm X-Received: by 2002:a05:6830:e88:b0:6dc:50a:cd28 with SMTP id dp8-20020a0568300e8800b006dc050acd28mr1514897otb.62.1706100799983; Wed, 24 Jan 2024 04:53:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706100799; cv=pass; d=google.com; s=arc-20160816; b=VMFJCA3oS9n7CuEov2Mk77e+peb3Ut5hC3zdsm6/d6bJmnUW2VnBAn8eyJkuj0Q4La n6WKwEYlj+3bLIhxv1AvIuoU6rW8k+uMmScNphZZj5Y2lpuOWVh+HW4eQPJkLBgz8rEs CH1se1ZuhN61azbcJ9m63Yp9M3KCnkXoGce0yqFJf5FFCyryHDA+xcHMaM/uNZuYJ6mM KWdRR6aCnrER31wy8zVcDKPL3TgMLga7iBo1z+AO61rG3bx4J/kmdihQyb6SCi9SUSBq l6rCZPoEFMpzuXu2003Q3J0pncyMp9RolehgvxjJc1MQaceEnv4AvM3JonUpuW08TU6T jA/A== 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; bh=U3bP/TLZzrjpnEIBLPJodnC8KbDW4b/2sT2nek0MY1s=; fh=cTOyeHIiotxFveWD397Up69SLR8Dqpy9YboYIfW0A00=; b=j87hEbIHS59ZhfWtE1Z4kYV4TyvBWutayyckDQe737jXozIgb4YEaVwrYPMnwCJC+P fALglZhZQf268047/Cgk7F9dCdFcsugf4VaVazZuj5j7OS/6IBXm6H60dwnstifmivfF pq4kF2svTRUlfGhMbxTzeox7hMl7OJW4YUaVNQlgI8nHE9tyfCa1BNSXiwAMTScR0n3w UGxKHNTKzYmzOOdMzYf9v8WIXOmvOsBjW31Y6AaLPZD/i0OpowWhY58c06cnOS8S4/Mm CrrT6BIFhyD2M3hXFSz6rIoxjKrNplqpWmasjzwLlg33/0mSMwj0gQI4el1oiRCTjnn9 K3AQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-36963-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36963-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id k1-20020aa78201000000b006d9b10a55aasi13428808pfi.393.2024.01.24.04.53.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 04:53:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36963-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-36963-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36963-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id EC2B1B2B1A7 for ; Wed, 24 Jan 2024 12:22:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E437633EA; Wed, 24 Jan 2024 12:22:28 +0000 (UTC) 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 F04856310C for ; Wed, 24 Jan 2024 12:22:25 +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=1706098947; cv=none; b=Q+Q5KjRno+6O6oUhcgDvh+j/0pDCzlrPJDoEdXrw0QpGaHziYKx7IQZM6rO1IC385Ej2WdFhDFxRIrcBLRQLctUdbtpxMrSGAPfEWKRtoHLqXu1A8WcblqzsV8sDsnpbE1/pOOMXAPyMkT0gUDi364BNBgu+LomU/2WybqsAe2k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706098947; c=relaxed/simple; bh=viEuHOnCMvFs1FiV9peHFb17kutxKUU/HIZcjaimZ5g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z83eAm/Bol6cnlAxqUZJFaiqi+N/2A7IbinFiurd6nnw/HxrxqF0iZ2o93OuS94KGTtdNoM/TnONKhvjFu2qp53YZnPoFuByy5dBk0InY7GMWxE4Vtx26dpOTeF9OW3AZZw136X2DSUMet+/sEFEsBSuBr21I+XUdKqlkiLqC9k= 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 1rScGd-0007o9-1C; Wed, 24 Jan 2024 13:22:07 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rScGc-0023Zg-2a; Wed, 24 Jan 2024 13:22:06 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rScGb-00341Y-37; Wed, 24 Jan 2024 13:22:05 +0100 From: Oleksij Rempel To: Sebastian Reichel , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Srinivas Kandagatla Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, Liam Girdwood , Mark Brown , "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, =?UTF-8?q?S=C3=B8ren=20Andersen?= Subject: [PATCH v2 5/8] nvmem: provide consumer access to cell size metrics Date: Wed, 24 Jan 2024 13:22:01 +0100 Message-Id: <20240124122204.730370-6-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240124122204.730370-1-o.rempel@pengutronix.de> References: <20240124122204.730370-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Add nvmem_cell_get_size() function to provide access to cell size metrics. In some cases we may get cell size less as consumer would expect it. So, nvmem_cell_write() would fail with incorrect buffer size. Signed-off-by: Oleksij Rempel --- drivers/nvmem/core.c | 25 +++++++++++++++++++++++++ include/linux/nvmem-consumer.h | 7 +++++++ 2 files changed, 32 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 980123fb4dde..a21e5649fcda 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1790,6 +1790,31 @@ int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len) EXPORT_SYMBOL_GPL(nvmem_cell_write); +/** + * nvmem_cell_get_size() - Get the size of a given nvmem cell + * @cell: nvmem cell to be queried. + * @bytes: Pointer to store the size of the cell in bytes. Can be NULL. + * @bits: Pointer to store the size of the cell in bits. Can be NULL. + * + * Return: 0 on success or negative on failure. + */ +int nvmem_cell_get_size(struct nvmem_cell *cell, size_t *bytes, size_t *bits) +{ + struct nvmem_cell_entry *entry = cell->entry; + + if (!entry->nvmem) + return -EINVAL; + + if (bytes) + *bytes = entry->bytes; + + if (bits) + *bits = entry->nbits; + + return 0; +} +EXPORT_SYMBOL_GPL(nvmem_cell_get_size); + static int nvmem_cell_read_common(struct device *dev, const char *cell_id, void *val, size_t count) { diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h index 34c0e58dfa26..bcb0e17e415d 100644 --- a/include/linux/nvmem-consumer.h +++ b/include/linux/nvmem-consumer.h @@ -56,6 +56,7 @@ void nvmem_cell_put(struct nvmem_cell *cell); void devm_nvmem_cell_put(struct device *dev, struct nvmem_cell *cell); void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len); int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len); +int nvmem_cell_get_size(struct nvmem_cell *cell, size_t *bytes, size_t *bits); int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val); int nvmem_cell_read_u16(struct device *dev, const char *cell_id, u16 *val); int nvmem_cell_read_u32(struct device *dev, const char *cell_id, u32 *val); @@ -128,6 +129,12 @@ static inline int nvmem_cell_write(struct nvmem_cell *cell, return -EOPNOTSUPP; } +static inline int nvmem_cell_get_size(struct nvmem_cell *cell, size_t *bytes, + size_t *bits) +{ + return -EOPNOTSUPP; +} + static inline int nvmem_cell_read_u8(struct device *dev, const char *cell_id, u8 *val) { -- 2.39.2