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] [day] [month] [year] [list]
Message-ID: <aScDqsBMAc_TeDVE@black.igk.intel.com>
Date: Wed, 26 Nov 2025 14:42:02 +0100
From: Andy Shevchenko <andriy.shevchenko@...el.com>
To: srini@...nel.org
Cc: gregkh@...uxfoundation.org, linux-kernel@...r.kernel.org,
	Heiko Stuebner <heiko@...ech.de>
Subject: Re: [PATCH 3/8] nvmem: Add driver for the eeprom in qnap-mcu
 controllers

On Fri, Nov 14, 2025 at 11:06:31AM +0000, srini@...nel.org wrote:
> 
> The qnap-mcu also has an eeprom connected to it, that contains some
> specific product-information like the mac addresses for the network
> interfaces.
> 
> Add a nvmem driver for it.

I have no problem with current code, but below some hints in case you want to
improve it.

...

+ device.h
+ err.h

> +#include <linux/mfd/qnap-mcu.h>
> +#include <linux/module.h>
> +#include <linux/nvmem-provider.h>
> +#include <linux/platform_device.h>
> +#include <linux/slab.h>

+ string.h
+ types.h

...

> +static int qnap_mcu_eeprom_read_block(struct qnap_mcu *mcu, unsigned int offset,
> +				      void *val, size_t bytes)
> +{
> +	const u8 cmd[] = { 0xf7, 0xa1, offset, bytes };
> +	u8 *reply;
> +	int ret = 0;
> +
> +	reply = kzalloc(bytes + sizeof(cmd), GFP_KERNEL);
> +	if (!reply)
> +		return -ENOMEM;

Using __free() from cleanup.h actually fits here and makes code easier to read.

> +	ret = qnap_mcu_exec(mcu, cmd, sizeof(cmd), reply, bytes + sizeof(cmd));
> +	if (ret)
> +		goto out;
> +
> +	/* First bytes must mirror the sent command */
> +	if (memcmp(cmd, reply, sizeof(cmd))) {
> +		ret = -EIO;
> +		goto out;
> +	}
> +
> +	memcpy(val, reply + sizeof(cmd), bytes);
> +
> +out:
> +	kfree(reply);
> +	return ret;
> +}

...

> +static int qnap_mcu_eeprom_probe(struct platform_device *pdev)
> +{

	struct device *parent = pdev->dev.parent;

> +	struct qnap_mcu *mcu = dev_get_drvdata(pdev->dev.parent);

	struct qnap_mcu *mcu = dev_get_drvdata(parent);

> +	struct nvmem_config nvcfg = {};
> +	struct nvmem_device *ndev;
> +
> +	nvcfg.dev = &pdev->dev;

> +	nvcfg.of_node = pdev->dev.parent->of_node;

	nvcfg.of_node = dev_of_node(parent);

(will need to include of.h, but ideally nvmem can be switched to fwnode)

> +	nvcfg.name = dev_name(&pdev->dev);
> +	nvcfg.id = NVMEM_DEVID_NONE;
> +	nvcfg.owner = THIS_MODULE;
> +	nvcfg.type = NVMEM_TYPE_EEPROM;
> +	nvcfg.read_only = true;
> +	nvcfg.root_only = false;
> +	nvcfg.reg_read = qnap_mcu_eeprom_read;
> +	nvcfg.size = QNAP_MCU_EEPROM_SIZE,
> +	nvcfg.word_size = 1,
> +	nvcfg.stride = 1,
> +	nvcfg.priv = mcu,
> +
> +	ndev = devm_nvmem_register(&pdev->dev, &nvcfg);

> +	if (IS_ERR(ndev))
> +		return PTR_ERR(ndev);
> +
> +	return 0;

	retrun PTR_ERR_OR_ZERO(...);

> +}

-- 
With Best Regards,
Andy Shevchenko



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ