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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <1fb5c223-fcd7-4789-9cd6-33c712457a0a@wanadoo.fr>
Date: Fri, 16 May 2025 17:48:38 +0200
From: Christophe JAILLET <christophe.jaillet@...adoo.fr>
To: dongxuyang@...incomputing.com
Cc: conor+dt@...nel.org, devicetree@...r.kernel.org,
 huangyifeng@...incomputing.com, krzk+dt@...nel.org,
 linmin@...incomputing.com, linux-kernel@...r.kernel.org,
 ningyu@...incomputing.com, p.zabel@...gutronix.de, robh@...nel.org
Subject: Re: [PATCH 2/2] reset: eswin: Add eic7700 reset driver

Le 14/05/2025 à 02:32, 
dongxuyang-sYo9T6QOUuK8M3too/+dENBPR1lH4CV8@...lic.gmane.org a écrit :
> From: Xuyang Dong <dongxuyang-sYo9T6QOUuK8M3too/+dENBPR1lH4CV8@...lic.gmane.org>
> 
> Add support for reset controller in eic7700 series chips.
> Provide functionality for asserting and deasserting resets
> on the chip.

...

> +#include <linux/err.h>
> +#include <linux/init.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/reset-controller.h>
> +#include <linux/slab.h>
> +#include <linux/types.h>
> +#include <linux/regmap.h>
> +#include <linux/mfd/syscon.h>

Would be better if fully alphabetically ordered.

> +
> +#define SYSCRG_CLEAR_BOOT_INFO_OFFSET (0x30C)

Unneeded ()

> +#define CLEAR_BOOT_FLAG_BIT BIT_ULL(0)

It is only used as a unsigned int parameter with regmap_set_bits(), so 
why ULL?

> +
> +#define SYSCRG_RESET_OFFSET (0x400)

Unneeded ()

...

> +/**
> + * eswin_reset_set() - program a device's reset
> + * @rcdev: reset controller entity
> + * @id: ID of the reset to toggle
> + * @assert: boolean flag to indicate assert or deassert
> + *
> + * This is a common internal function used to assert or deassert a device's
> + * reset by clear and set the reset bit. The device's reset is asserted if the
> + * @assert argument is true, or deasserted if @assert argument is false.
> + *
> + * Return: 0 for successful request, else a corresponding error value
> + */
> +static int eswin_reset_set(struct reset_controller_dev *rcdev, unsigned long id,
> +			   bool assert)
> +{
> +	struct eswin_reset_data *data = to_eswin_reset_data(rcdev);
> +	struct eswin_reset_control *control;
> +	int ret;
> +
> +	control = idr_find(&data->idr, id);
> +
> +	dev_dbg(rcdev->dev, "dev_id 0x%x reset_bit 0x%x assert 0x%x\r\n",
> +		control->dev_id, control->reset_bit, assert);

We test of control is NULL the line after. So if it can happen, it would 
crash here.

> +
> +	if (!control)
> +		return -EINVAL;
> +
> +	if (assert) {
> +		ret = regmap_clear_bits(data->regmap,
> +					SYSCRG_RESET_OFFSET +
> +						control->dev_id * sizeof(u32),
> +					control->reset_bit);
> +	} else {
> +		ret = regmap_set_bits(data->regmap,
> +				      SYSCRG_RESET_OFFSET +
> +					      control->dev_id * sizeof(u32),
> +				      control->reset_bit);
> +	}

No need fo { } around each of these branches.

> +
> +	return ret;
> +}
> +
> +static int eswin_reset_reset(struct reset_controller_dev *rcdev,
> +			     unsigned long id)
> +{
> +	int ret;
> +
> +	ret = eswin_reset_set(rcdev, id, true);

Would it make sense to use eswin_reset_assert()?

> +	if (ret != 0)
> +		return ret;
> +
> +	usleep_range(10, 15);
> +	ret = eswin_reset_set(rcdev, id, false);

Would it make sense to use eswin_reset_deassert()?

> +	if (ret != 0)
> +		return ret;
> +
> +	return 0;
> +}
> +
> +static int eswin_reset_assert(struct reset_controller_dev *rcdev,
> +			      unsigned long id)
> +{
> +	return eswin_reset_set(rcdev, id, true);
> +}
> +
> +static int eswin_reset_deassert(struct reset_controller_dev *rcdev,
> +				unsigned long id)
> +{
> +	return eswin_reset_set(rcdev, id, false);
> +}

...

> +static int eswin_reset_of_xlate_lookup_id(int id, void *p, void *data)
> +{
> +	struct of_phandle_args *reset_spec = (struct of_phandle_args *)data;
> +	struct eswin_reset_control *slot_control =
> +		(struct eswin_reset_control *)p;
> +
> +	if (reset_spec->args[0] == slot_control->dev_id &&
> +	    reset_spec->args[1] == slot_control->reset_bit)
> +		return id;
> +	else

Unneeded else.

> +		return 0;
> +}
> +
> +/**
> + * eswin_reset_of_xlate() - translate a set of OF arguments to a reset ID
> + * @rcdev: reset controller entity
> + * @reset_spec: OF reset argument specifier
> + *
> + * This function performs the translation of the reset argument specifier
> + * values defined in a reset consumer device node. The function allocates a
> + * reset control structure for that device reset, and will be used by the
> + * driver for performing any reset functions on that reset. An idr structure
> + * is allocated and used to map to the reset control structure. This idr
> + * is used by the driver to do reset lookups.
> + *
> + * Return: 0 for successful request, else a corresponding error value
> + */
> +static int eswin_reset_of_xlate(struct reset_controller_dev *rcdev,
> +				const struct of_phandle_args *reset_spec)
> +{
> +	struct eswin_reset_data *data = to_eswin_reset_data(rcdev);
> +	struct eswin_reset_control *control;
> +	int ret;
> +
> +	if (WARN_ON(reset_spec->args_count != rcdev->of_reset_n_cells))
> +		return -EINVAL;
> +
> +	ret = idr_for_each(&data->idr, eswin_reset_of_xlate_lookup_id,
> +			   (void *)reset_spec);
> +	if (ret != 0)

if (ret)

> +		return ret;
> +
> +	control = devm_kzalloc(data->dev, sizeof(*control), GFP_KERNEL);
> +	if (!control)
> +		return -ENOMEM;
> +
> +	control->dev_id = reset_spec->args[0];
> +	control->reset_bit = reset_spec->args[1];
> +
> +	return idr_alloc(&data->idr, control, 0, 0, GFP_KERNEL);
> +}
> +
> +static const struct of_device_id eswin_reset_dt_ids[] = {
> +	{
> +		.compatible = "eswin,eic7700-reset",
> +	},
> +	{ /* sentinel */ },

No need for a trailing , after a terminator.

> +};
> +
> +static int eswin_reset_probe(struct platform_device *pdev)
> +{
> +	struct eswin_reset_data *data;
> +	struct device *parent;
> +
> +	parent = pdev->dev.parent;
> +	if (!parent) {
> +		dev_err(&pdev->dev, "no parent\n");
> +		return -ENODEV;
> +	}
> +
> +	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> +	if (!data)
> +		return -ENOMEM;
> +
> +	data->regmap = syscon_node_to_regmap(parent->of_node);
> +	if (IS_ERR(data->regmap)) {
> +		dev_err(&pdev->dev, "failed to get parent regmap\n");
> +		return PTR_ERR(data->regmap);
> +	}
> +
> +	platform_set_drvdata(pdev, data);
> +
> +	data->rcdev.owner = THIS_MODULE;
> +	data->rcdev.ops = &eswin_reset_ops;
> +	data->rcdev.of_node = pdev->dev.of_node;
> +	data->rcdev.of_reset_n_cells = 2;
> +	data->rcdev.of_xlate = eswin_reset_of_xlate;
> +	data->rcdev.dev = &pdev->dev;
> +	data->dev = &pdev->dev;
> +	idr_init(&data->idr);
> +
> +	/*clear boot flag so u84 and scpu could be reseted by software*/

Missing spaces at the start and the end of the comment.

> +	regmap_set_bits(data->regmap, SYSCRG_CLEAR_BOOT_INFO_OFFSET,
> +			CLEAR_BOOT_FLAG_BIT);
> +	msleep(50);
> +	platform_set_drvdata(pdev, data);
> +
> +	return devm_reset_controller_register(&pdev->dev, &data->rcdev);
> +}

...

CJ

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ