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]
Date:	Fri, 21 Jun 2013 16:15:23 +0100
From:	Mark Brown <broonie@...nel.org>
To:	Steve Twiss <stwiss.opensource@...semi.com>
Cc:	Liam Girdwood <lgirdwood@...il.com>,
	David Dajun Chen <david.chen@...semi.com>,
	Guennadi Liakhovetski <g.liakhovetski@....de>,
	LKML <linux-kernel@...r.kernel.org>
Subject: Re: [RFC V1] COMMIT 1: DA9210 driver files

On Thu, Jun 20, 2013 at 02:42:03PM +0100, Steve Twiss wrote:

> @@ -293,6 +293,13 @@ config REGULATOR_LP8788
>  	help
>  	  This driver supports LP8788 voltage regulator chip.
>  
> +config REGULATOR_DA9210
> +	bool "Dialog Semiconductor DA9210 Regulator"
> +	depends on I2C=y
> +	select REGMAP_I2C
> +	help
> +	  Support for the Dialog Semiconductor DA9210 chip.
> +
>  config REGULATOR_PCF50633

This file ought to be kept sorted though it seems that's not been
happening, and I'm not seeing any reason why this can't be a tristate.

> +#define DRIVER_NAME	"da9210"

Why?

> +struct da9210 {
> +	struct i2c_client *i2c;
> +	struct device *dev;
> +	struct mutex io_mutex;

Why do you need an I/O lock?

> +static int da9210_enable(struct regulator_dev *rdev);
> +static int da9210_set_voltage(struct regulator_dev *rdev, int min_uV,
> +			      int max_uV, unsigned *selector);
> +static int da9210_get_voltage(struct regulator_dev *rdev);
> +static int da9210_set_current_limit(struct regulator_dev *rdev, int min_uA,
> +				    int max_uA);
> +static int da9210_get_current_limit(struct regulator_dev *rdev);
> +
> +static struct regulator_ops da9210_buck_ops = {
> +	.enable = da9210_enable,
> +	.disable = regulator_disable_regmap,
> +	.is_enabled = regulator_is_enabled_regmap,
> +	.set_voltage = da9210_set_voltage,
> +	.get_voltage = da9210_get_voltage,
> +	.list_voltage = regulator_list_voltage_linear,
> +	.set_current_limit = da9210_set_current_limit,
> +	.get_current_limit = da9210_get_current_limit,
> +};

Drivers are normally written to avoid forward declarations like this.

> +static struct regulator_consumer_supply __initdata def_da9210_consumers[] = {
> +	REGULATOR_SUPPLY("DA9210", NULL),
> +};
> +
> +static struct regulator_init_data __initdata default_da9210_constraints = {
> +	.constraints = {

This is not at all sensible, there's a good solid reason why regulator
drivers don't generally do this...  please review the machine interface
and its purpose.

> +static int da9210_set_voltage(struct regulator_dev *rdev, int min_uV,
> +			      int max_uV, unsigned *selector)
> +{
> +	struct da9210 *chip = rdev_get_drvdata(rdev);
> +	int val;
> +	int ret;
> +
> +	val = regulator_map_voltage_linear(rdev, min_uV, max_uV);
> +	if (val < 0)
> +		return -EINVAL;
> +
> +	ret = regmap_update_bits(chip->regmap, DA9210_REG_VBUCK_A,
> +				 DA9210_VBUCK_MASK, val);
> +	return ret;
> +}

Why not just use set_voltage_sel()?

> +static int da9210_get_voltage_sel(struct regulator_dev *rdev)
> +{
> +	struct da9210 *chip = rdev_get_drvdata(rdev);
> +	unsigned int data;
> +	int sel;
> +	int ret;
> +
> +	ret = regmap_read(chip->regmap, DA9210_REG_VBUCK_A, &data);
> +	if (ret < 0)
> +		return ret;
> +
> +	sel = (data & DA9210_VBUCK_MASK) >> DA9210_VBUCK_SHIFT;
> +	sel -= DA9210_VBUCK_BIAS;
> +	if (sel < 0)
> +		sel = 0;
> +	if (sel >= chip->info->n_steps)
> +		sel = chip->info->n_steps - 1;

This looks like poor error handling, if the value is out of range isn't
there an error state?

> +static int da9210_get_voltage(struct regulator_dev *rdev)
> +{
> +	struct da9210 *chip = rdev_get_drvdata(rdev);
> +	int sel = da9210_get_voltage_sel(rdev);
> +
> +	if (sel < 0)
> +		return sel;
> +
> +	return (chip->info->step_uV * sel) + chip->info->min_uV;
> +}

Why are you open coding core functionalit?

> +static int da9210_enable(struct regulator_dev *rdev)
> +{
> +	return regulator_enable_regmap(rdev);
> +}

This is pointless, just use the generic function directly.

> +
> +	dev_info(chip->dev, "Device DA9210 detected.\n");

This is just noise.

> +static const struct i2c_device_id da9210_i2c_id[] = {
> +	{DRIVER_NAME, 0},
> +	{},

Just use the string.

> +static struct i2c_driver da9210_regulator_driver = {
> +	.driver = {
> +		.name = DRIVER_NAME,

Similarly here.

> +		.owner = THIS_MODULE,
> +		},

Indentation.

> +static int __init da9210_regulator_init(void)
> +{
> +	int ret;
> +
> +	ret = i2c_add_driver(&da9210_regulator_driver);
> +	if (0 != ret)
> +		pr_err("Failed to register da9210 I2C driver\n");
> +
> +	return ret;
> +}
> +
> +subsys_initcall(da9210_regulator_init);

Just use module_platform_driver() now we have probe deferral.

> +/*
> + * Registers bits
> + */
> +/* DA9210_REG_PAGE_CON (addr=0x00) */
> +#define	DA9210_PEG_PAGE_SHIFT			0
> +#define	DA9210_REG_PAGE_MASK			0x0F
> +/* On I2C registers 0x00 - 0xFF */
> +#define	DA9210_REG_PAGE0			0
> +/* On I2C registers 0x100 - 0x1FF */
> +#define	DA9210_REG_PAGE2			2
> +#define	DA9210_PAGE_WRITE_MODE			0x00
> +#define	DA9210_REPEAT_WRITE_MODE		0x40
> +#define	DA9210_PAGE_REVERT			0x80

This looks liike you should be using a regmap range.

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ