lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <dixmyhyj6b66vyizfotpqw6yzaavi2o2mauloa5x6zn3qgk5ub@huoal5ucdd44>
Date: Thu, 1 May 2025 22:59:19 +0200
From: Sebastian Reichel <sebastian.reichel@...labora.com>
To: Oleksij Rempel <o.rempel@...gutronix.de>
Cc: Srinivas Kandagatla <srinivas.kandagatla@...aro.org>, 
	Benson Leung <bleung@...omium.org>, Tzung-Bi Shih <tzungbi@...nel.org>, 
	Daniel Lezcano <daniel.lezcano@...aro.org>, kernel@...gutronix.de, linux-kernel@...r.kernel.org, 
	Liam Girdwood <lgirdwood@...il.com>, Mark Brown <broonie@...nel.org>, 
	"Rafael J. Wysocki" <rafael@...nel.org>, Zhang Rui <rui.zhang@...el.com>, 
	Lukasz Luba <lukasz.luba@....com>, linux-pm@...r.kernel.org, 
	Søren Andersen <san@...v.dk>, Guenter Roeck <groeck@...omium.org>, 
	Matti Vaittinen <mazziesaccount@...il.com>, Ahmad Fatoum <a.fatoum@...gutronix.de>, 
	Andrew Morton <akpm@...ux-foundation.org>, chrome-platform@...ts.linux.dev
Subject: Re: [PATCH v9 4/7] nvmem: provide consumer access to cell size
 metrics

Hi,

On Tue, Apr 22, 2025 at 10:57:14AM +0200, Oleksij Rempel wrote:
> 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 <o.rempel@...gutronix.de>
> ---
> changes v6:
> - update function comment for nvmem_cell_get_size()
> ---

This is also needed for the following patch:

https://lore.kernel.org/linux-pm/20250321161449.1175473-1-jberring@redhat.com/

Reviewed-by: Sebastian Reichel <sebastian.reichel@...labora.com>

-- Sebastian

>  drivers/nvmem/core.c           | 29 +++++++++++++++++++++++++++++
>  include/linux/nvmem-consumer.h |  7 +++++++
>  2 files changed, 36 insertions(+)
> 
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index fff85bbf0ecd..754a9448c39d 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -1828,6 +1828,35 @@ int nvmem_cell_write(struct nvmem_cell *cell, void *buf, size_t len)
>  
>  EXPORT_SYMBOL_GPL(nvmem_cell_write);
>  
> +/**
> + * nvmem_cell_get_size() - Retrieve the storage size of an NVMEM cell.
> + * @cell: Pointer to the NVMEM cell structure.
> + * @bytes: Optional pointer to store the cell size in bytes (can be NULL).
> + * @bits: Optional pointer to store the cell size in bits (can be NULL).
> + *
> + * This function allows consumers to retrieve the size of a specific NVMEM
> + * cell before performing read/write operations. It is useful for validating
> + * buffer sizes to prevent mismatched writes.
> + *
> + * 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.5
> 

Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ