[PATCH linux dev-4.10] drivers: hwmon: occ: Add "master" attribute and remove status files
Joel Stanley
joel at jms.id.au
Fri Jun 16 16:27:52 AEST 2017
2017-06-15 5:56 GMT+09:30 Eddie James <eajames at linux.vnet.ibm.com>:
> From: "Edward A. James" <eajames at us.ibm.com>
>
> Driver did not remove status device attributes when the device was
> unloaded.
>
> Signed-off-by: Edward A. James <eajames at us.ibm.com>
Applied to dev-4.10.
> ---
> drivers/hwmon/occ/common.c | 39 ++++++++++++++++++++++++++++-----------
> drivers/hwmon/occ/common.h | 1 +
> drivers/hwmon/occ/p8_i2c.c | 10 ++++++++++
> drivers/hwmon/occ/p9_sbe.c | 10 ++++++++++
> 4 files changed, 49 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/hwmon/occ/common.c b/drivers/hwmon/occ/common.c
> index bee64cd..f34b400 100644
> --- a/drivers/hwmon/occ/common.c
> +++ b/drivers/hwmon/occ/common.c
> @@ -10,8 +10,9 @@
> #include <asm/unaligned.h>
> #include "common.h"
>
> -#define OCC_NUM_STATUS_ATTRS 6
> +#define OCC_NUM_STATUS_ATTRS 7
>
> +#define OCC_STAT_MASTER 0x80
> #define OCC_STAT_ACTIVE 0x01
> #define OCC_EXT_STAT_DVFS_OT 0x80
> #define OCC_EXT_STAT_DVFS_POWER 0x40
> @@ -236,21 +237,24 @@ static ssize_t occ_show_status(struct device *dev,
>
> switch (sattr->index) {
> case 0:
> - val = header->status & OCC_STAT_ACTIVE;
> + val = header->status & OCC_STAT_MASTER;
> break;
> case 1:
> - val = header->ext_status & OCC_EXT_STAT_DVFS_OT;
> + val = header->status & OCC_STAT_ACTIVE;
> break;
> case 2:
> - val = header->ext_status & OCC_EXT_STAT_DVFS_POWER;
> + val = header->ext_status & OCC_EXT_STAT_DVFS_OT;
> break;
> case 3:
> - val = header->ext_status & OCC_EXT_STAT_MEM_THROTTLE;
> + val = header->ext_status & OCC_EXT_STAT_DVFS_POWER;
> break;
> case 4:
> - val = header->ext_status & OCC_EXT_STAT_QUICK_DROP;
> + val = header->ext_status & OCC_EXT_STAT_MEM_THROTTLE;
> break;
> case 5:
> + val = header->ext_status & OCC_EXT_STAT_QUICK_DROP;
> + break;
> + case 6:
> val = header->occ_state;
> break;
> }
> @@ -1061,29 +1065,33 @@ int occ_create_status_attrs(struct occ *occ)
> return -ENOMEM;
>
> occ->status_attrs[0] =
> - (struct sensor_device_attribute)SENSOR_ATTR(occ_active, 0444,
> + (struct sensor_device_attribute)SENSOR_ATTR(occ_master, 0444,
> occ_show_status,
> NULL, 0);
> occ->status_attrs[1] =
> + (struct sensor_device_attribute)SENSOR_ATTR(occ_active, 0444,
> + occ_show_status,
> + NULL, 0);
> + occ->status_attrs[2] =
> (struct sensor_device_attribute)SENSOR_ATTR(occ_dvfs_ot, 0444,
> occ_show_status,
> NULL, 1);
> - occ->status_attrs[2] =
> + occ->status_attrs[3] =
> (struct sensor_device_attribute)SENSOR_ATTR(occ_dvfs_power,
> 0444,
> occ_show_status,
> NULL, 2);
> - occ->status_attrs[3] =
> + occ->status_attrs[4] =
> (struct sensor_device_attribute)SENSOR_ATTR(occ_mem_throttle,
> 0444,
> occ_show_status,
> NULL, 3);
> - occ->status_attrs[4] =
> + occ->status_attrs[5] =
> (struct sensor_device_attribute)SENSOR_ATTR(occ_quick_drop,
> 0444,
> occ_show_status,
> NULL, 4);
> - occ->status_attrs[5] =
> + occ->status_attrs[6] =
> (struct sensor_device_attribute)SENSOR_ATTR(occ_status, 0444,
> occ_show_status,
> NULL, 5);
> @@ -1097,3 +1105,12 @@ int occ_create_status_attrs(struct occ *occ)
>
> return 0;
> }
> +
> +void occ_remove_status_attrs(struct occ *occ)
> +{
> + int i;
> +
> + for (i = 0; i < OCC_NUM_STATUS_ATTRS; ++i)
> + device_remove_file(occ->bus_dev,
> + &occ->status_attrs[i].dev_attr);
> +}
> diff --git a/drivers/hwmon/occ/common.h b/drivers/hwmon/occ/common.h
> index ad21538..a6582a7 100644
> --- a/drivers/hwmon/occ/common.h
> +++ b/drivers/hwmon/occ/common.h
> @@ -137,5 +137,6 @@ struct occ {
> int occ_update_response(struct occ *occ);
> int occ_setup_sensor_attrs(struct occ *occ);
> int occ_create_status_attrs(struct occ *occ);
> +void occ_remove_status_attrs(struct occ *occ);
>
> #endif /* __OCC_COMMON_H__ */
> diff --git a/drivers/hwmon/occ/p8_i2c.c b/drivers/hwmon/occ/p8_i2c.c
> index a2f10ea..a4d9965 100644
> --- a/drivers/hwmon/occ/p8_i2c.c
> +++ b/drivers/hwmon/occ/p8_i2c.c
> @@ -245,6 +245,15 @@ static int p8_i2c_occ_probe(struct i2c_client *client,
> return 0;
> }
>
> +static int p8_i2c_occ_remove(struct i2c_client *client)
> +{
> + struct occ *occ = dev_get_drvdata(&client->dev);
> +
> + occ_remove_status_attrs(occ);
> +
> + return 0;
> +}
> +
> static const struct of_device_id p8_i2c_occ_of_match[] = {
> { .compatible = "ibm,p8-occ-hwmon" },
> {}
> @@ -260,6 +269,7 @@ static int p8_i2c_occ_probe(struct i2c_client *client,
> .of_match_table = p8_i2c_occ_of_match,
> },
> .probe = p8_i2c_occ_probe,
> + .remove = p8_i2c_occ_remove,
> .address_list = p8_i2c_occ_addr,
> };
>
> diff --git a/drivers/hwmon/occ/p9_sbe.c b/drivers/hwmon/occ/p9_sbe.c
> index c70858d..6226f6f 100644
> --- a/drivers/hwmon/occ/p9_sbe.c
> +++ b/drivers/hwmon/occ/p9_sbe.c
> @@ -151,6 +151,15 @@ static int p9_sbe_occ_probe(struct platform_device *pdev)
> return p9_sbe_occ_setup(p9_sbe_occ);
> }
>
> +static int p9_sbe_occ_remove(struct platform_device *pdev)
> +{
> + struct occ *occ = platform_get_drvdata(pdev);
> +
> + occ_remove_status_attrs(occ);
> +
> + return 0;
> +}
> +
> static const struct of_device_id p9_sbe_occ_of_match[] = {
> { .compatible = "ibm,p9-occ-hwmon" },
> { },
> @@ -162,6 +171,7 @@ static int p9_sbe_occ_probe(struct platform_device *pdev)
> .of_match_table = p9_sbe_occ_of_match,
> },
> .probe = p9_sbe_occ_probe,
> + .remove = p9_sbe_occ_remove,
> };
>
> module_platform_driver(p9_sbe_occ_driver);
> --
> 1.8.3.1
>
More information about the openbmc
mailing list