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: <917858C9-2E51-442F-80A2-420A7460477D@fb.com>
Date:   Thu, 30 May 2019 18:55:17 +0000
From:   Vijay Khemka <vijaykhemka@...com>
To:     Guenter Roeck <linux@...ck-us.net>,
        Jean Delvare <jdelvare@...e.com>,
        Jonathan Corbet <corbet@....net>,
        "linux-hwmon@...r.kernel.org" <linux-hwmon@...r.kernel.org>,
        "linux-doc@...r.kernel.org" <linux-doc@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
CC:     "joel@....id.au" <joel@....id.au>,
        "linux-aspeed@...ts.ozlabs.org" <linux-aspeed@...ts.ozlabs.org>,
        Sai Dasari <sdasari@...com>,
        "Greg Kroah-Hartman" <gregkh@...uxfoundation.org>
Subject: Re: [PATCH 1/2] hwmon: pmbus: Add Infineon PXE1610 VR driver



On 5/29/19, 6:01 PM, "Guenter Roeck" <groeck7@...il.com on behalf of linux@...ck-us.net> wrote:

    On 5/29/19 3:35 PM, Vijay Khemka wrote:
    > Added pmbus driver for the new device Infineon pxe1610
    > voltage regulator. It also supports similar family device
    > PXE1110 and PXM1310.
    > 
    > Signed-off-by: Vijay Khemka <vijaykhemka@...com>
    > ---
    >   drivers/hwmon/pmbus/Kconfig   |   9 +++
    >   drivers/hwmon/pmbus/Makefile  |   1 +
    >   drivers/hwmon/pmbus/pxe1610.c | 119 ++++++++++++++++++++++++++++++++++
    >   3 files changed, 129 insertions(+)
    >   create mode 100644 drivers/hwmon/pmbus/pxe1610.c
    > 
    > diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
    > index 30751eb9550a..338ef9b5a395 100644
    > --- a/drivers/hwmon/pmbus/Kconfig
    > +++ b/drivers/hwmon/pmbus/Kconfig
    > @@ -154,6 +154,15 @@ config SENSORS_MAX8688
    >   	  This driver can also be built as a module. If so, the module will
    >   	  be called max8688.
    >   
    > +config SENSORS_PXE1610
    > +	tristate "Infineon PXE1610"
    > +	help
    > +	  If you say yes here you get hardware monitoring support for Infineon
    > +	  PXE1610.
    > +
    > +	  This driver can also be built as a module. If so, the module will
    > +	  be called pxe1610.
    > +
    >   config SENSORS_TPS40422
    >   	tristate "TI TPS40422"
    >   	help
    > diff --git a/drivers/hwmon/pmbus/Makefile b/drivers/hwmon/pmbus/Makefile
    > index 2219b9300316..b0fbd017a91a 100644
    > --- a/drivers/hwmon/pmbus/Makefile
    > +++ b/drivers/hwmon/pmbus/Makefile
    > @@ -18,6 +18,7 @@ obj-$(CONFIG_SENSORS_MAX20751)	+= max20751.o
    >   obj-$(CONFIG_SENSORS_MAX31785)	+= max31785.o
    >   obj-$(CONFIG_SENSORS_MAX34440)	+= max34440.o
    >   obj-$(CONFIG_SENSORS_MAX8688)	+= max8688.o
    > +obj-$(CONFIG_SENSORS_PXE1610)	+= pxe1610.o
    >   obj-$(CONFIG_SENSORS_TPS40422)	+= tps40422.o
    >   obj-$(CONFIG_SENSORS_TPS53679)	+= tps53679.o
    >   obj-$(CONFIG_SENSORS_UCD9000)	+= ucd9000.o
    > diff --git a/drivers/hwmon/pmbus/pxe1610.c b/drivers/hwmon/pmbus/pxe1610.c
    > new file mode 100644
    > index 000000000000..01e267944df5
    > --- /dev/null
    > +++ b/drivers/hwmon/pmbus/pxe1610.c
    > @@ -0,0 +1,119 @@
    > +// SPDX-License-Identifier: GPL-2.0+
    > +/*
    > + * Hardware monitoring driver for Infineon PXE1610
    > + *
    > + * Copyright (c) 2019 Facebook Inc
    > + *
    > + */
    > +
    > +#include <linux/err.h>
    > +#include <linux/i2c.h>
    > +#include <linux/init.h>
    > +#include <linux/kernel.h>
    > +#include <linux/module.h>
    > +#include "pmbus.h"
    > +
    > +/*
    > + * Identify chip parameters.
    > + */
    > +static int pxe1610_identify(struct i2c_client *client,
    > +			  struct pmbus_driver_info *info)
    
    Please align continuation lines with '('.
Ack.
    
    > +{
    > +	if (pmbus_check_byte_register(client, 0, PMBUS_VOUT_MODE)) {
    > +		int vout_mode;
    > +
    > +		vout_mode = pmbus_read_byte_data(client, 0, PMBUS_VOUT_MODE);
    
    pmbus_read_byte_data() can return an error. Calling pmbus_check_byte_register()
    doesn't really add any value here, since the second call can still fail,
    which needs to be checked.
Ack.
    
    > +		switch (vout_mode & 0x1f) {
    > +		case 1:
    > +			info->vrm_version = vr12;
    > +		break;
    
    Alignment is off.
Ack.
    
    > +		case 2:
    > +			info->vrm_version = vr13;
    > +		break;
    
    Same here.
    
    > +		default:
    > +			return -ENODEV;
    > +		}
    > +	}
    > +	return 0;
    > +}
    > +
    > +static int pxe1610_probe(struct i2c_client *client,
    > +			 const struct i2c_device_id *id)
    > +{
    > +	struct pmbus_driver_info *info;
    > +	u8 buf[I2C_SMBUS_BLOCK_MAX];
    > +	int ret;
    > +
    > +	if (!i2c_check_functionality(client->adapter,
    > +				     I2C_FUNC_SMBUS_READ_BYTE_DATA
    > +				| I2C_FUNC_SMBUS_READ_WORD_DATA
    > +				| I2C_FUNC_SMBUS_READ_BLOCK_DATA))
    > +		return -ENODEV;
    > +
    > +	/* By default this device doesn't boot to page 0, so set page 0
    > +	 * to access all pmbus registers.
    > +	 */
    
    Please use standard multi-line comments.
Ack.
    
    > +	i2c_smbus_write_byte_data(client, 0, 0);
    > +
    
    Please use the PMBUS_PAGE command definition.
Will use.
    
    I wonder if it would make sense to initialize currpage in the core to an unreasonable
    number for multi-page chips, but I guess that is a different question.
    
    > +	/* Read Manufacturer id */
    > +	ret = i2c_smbus_read_block_data(client, PMBUS_MFR_ID, buf);
    > +	if (ret < 0) {
    > +		dev_err(&client->dev, "Failed to read PMBUS_MFR_ID\n");
    > +		return ret;
    > +	}
    > +	if (ret != 2 || strncmp(buf, "XP", strlen("XP"))) {
    
    The strlen() is really unnecessary here. Just use 2 (and a define
    for it if you like).
Ack
    
    > +		dev_err(&client->dev, "MFR_ID unrecognised\n");
    
    unrecognized. Oh well, turns out unrecognised is the British spelling and
    just as valid, so feel free to keep it if you like.
    
    > +		return -ENODEV;
    > +	}
    > +
    > +	info = devm_kzalloc(&client->dev, sizeof(struct pmbus_driver_info),
    > +			    GFP_KERNEL);
    > +	if (!info)
    > +		return -ENOMEM;
    > +
    > +	info->format[PSC_VOLTAGE_IN] = linear;
    > +	info->format[PSC_VOLTAGE_OUT] = vid;
    > +	info->format[PSC_CURRENT_IN] = linear;
    > +	info->format[PSC_CURRENT_OUT] = linear;
    > +	info->format[PSC_POWER] = linear;
    > +	info->format[PSC_TEMPERATURE] = linear;
    > +
    > +	info->func[0] = PMBUS_HAVE_VIN
    > +		| PMBUS_HAVE_VOUT | PMBUS_HAVE_IIN
    > +		| PMBUS_HAVE_IOUT | PMBUS_HAVE_PIN
    > +		| PMBUS_HAVE_POUT | PMBUS_HAVE_TEMP
    > +		| PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT
    > +		| PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP;
    > +	info->func[1] = info->func[0];
    > +	info->func[2] = info->func[0];
    > +
    > +	info->pages = id->driver_data;
    > +	info->identify = pxe1610_identify;
    > +
    
    It doesn't really add value to initialize all these parameters manually.
    I would suggest to use the approach from tps53679.c, ie have a static
    structure and use devm_kmemdup() to pass a copy to pmbus_do_probe().
Will look into this.
    
    > +	return pmbus_do_probe(client, id, info);
    > +}
    > +
    > +static const struct i2c_device_id pxe1610_id[] = {
    > +	{"pxe1610", 3},
    > +	{"pxe1110", 3},
    > +	{"pxm1310", 3},    

    Unless there are chips with different page counts in the queue, using
    driver_data to pass the number of pages does not add any value. Just
    set num_pages to 3.
    
    If you like, feel free to use a define instead of a constant.
Ack.    

    > +	{}
    > +};
    > +
    > +MODULE_DEVICE_TABLE(i2c, pxe1610_id);
    > +
    > +/* This is the driver that will be inserted */
    
    This comment does not add any value.
    
    > +static struct i2c_driver pxe1610_driver = {
    > +	.driver = {
    > +		   .name = "pxe1610",
    > +		   },
    > +	.probe = pxe1610_probe,
    > +	.remove = pmbus_do_remove,
    > +	.id_table = pxe1610_id,
    > +};
    > +
    > +module_i2c_driver(pxe1610_driver);
    > +
    > +MODULE_AUTHOR("Vijay Khemka <vijaykhemka@...com>");
    > +MODULE_DESCRIPTION("PMBus driver for Infineon PXE1610, PXE1110 and PXM1310");
    > +MODULE_LICENSE("GPL");
    > 
    
    

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ