RE: [PATCH] hwmon: (amd_energy) fix allocation of hwmon_channel_info config

2021-01-07 Thread Chatradhi, Naveen Krishna
[AMD Official Use Only - Approved for External Use]

Hi Guenter,

>> No, because you are not in the approval path (you did not send the patch to 
>> me). Reviewed-by: or Acked-by: would be more appropriate.

Got it, my mistake, please use 
Acked-by: Naveen Krishna Chatradhi 

Regards,
Naveenk

-Original Message-
From: Guenter Roeck  On Behalf Of Guenter Roeck
Sent: Friday, January 8, 2021 11:47 AM
To: Chatradhi, Naveen Krishna ; David Arcari 
; linux-hw...@vger.kernel.org
Cc: Jean Delvare ; linux-kernel@vger.kernel.org; 
sta...@vger.kernel.org
Subject: Re: [PATCH] hwmon: (amd_energy) fix allocation of hwmon_channel_info 
config

[CAUTION: External Email]

On 1/7/21 9:49 PM, Chatradhi, Naveen Krishna wrote:
> [AMD Official Use Only - Approved for External Use]
>
> Hi David,
>
> Thank you for noticing and submitting a fix. You may use
> Signed-off-by: Naveen Krishna Chatradhi 
>

No, because you are not in the approval path (you did not send the patch to 
me). Reviewed-by: or Acked-by: would be more appropriate.

Genter

> Regards,
> Naveenk
>
> -Original Message-
> From: David Arcari 
> Sent: Thursday, January 7, 2021 8:17 PM
> To: linux-hw...@vger.kernel.org
> Cc: David Arcari ; Chatradhi, Naveen Krishna 
> ; Jean Delvare ; 
> Guenter Roeck ; linux-kernel@vger.kernel.org; 
> sta...@vger.kernel.org
> Subject: [PATCH] hwmon: (amd_energy) fix allocation of 
> hwmon_channel_info config
>
> [CAUTION: External Email]
>
> hwmon, specifically hwmon_num_channel_attrs, expects the config array in the 
> hwmon_channel_info structure to be terminated by a zero entry.  amd_energy 
> does not honor this convention.  As result, a KASAN warning is possible.  Fix 
> this by adding an additional entry and setting it to zero.
>
> Fixes: 8abee9566b7e ("hwmon: Add amd_energy driver to report energy 
> counters")
>
> Signed-off-by: David Arcari 
> Cc: Naveen Krishna Chatradhi  [naveenk:] 
> Signed-off-by: Naveen Krishna Chatradhi 
> Cc: Jean Delvare 
> Cc: Guenter Roeck 
> Cc: linux-kernel@vger.kernel.org
> Cc: sta...@vger.kernel.org
> ---
>  drivers/hwmon/amd_energy.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hwmon/amd_energy.c b/drivers/hwmon/amd_energy.c 
> index 9b306448b7a0..822c2e74b98d 100644
> --- a/drivers/hwmon/amd_energy.c
> +++ b/drivers/hwmon/amd_energy.c
> @@ -222,7 +222,7 @@ static int amd_create_sensor(struct device *dev,
>  */
> cpus = num_present_cpus() / num_siblings;
>
> -   s_config = devm_kcalloc(dev, cpus + sockets,
> +   s_config = devm_kcalloc(dev, cpus + sockets + 1,
> sizeof(u32), GFP_KERNEL);
> if (!s_config)
> return -ENOMEM;
> @@ -254,6 +254,7 @@ static int amd_create_sensor(struct device *dev,
> scnprintf(label_l[i], 10, "Esocket%u", (i - cpus));
> }
>
> +   s_config[i] = 0;
> return 0;
>  }
>
> --
> 2.18.1
>


RE: [PATCH] hwmon: (amd_energy) fix allocation of hwmon_channel_info config

2021-01-07 Thread Chatradhi, Naveen Krishna
[AMD Official Use Only - Approved for External Use]

Hi David,

Thank you for noticing and submitting a fix. You may use
Signed-off-by: Naveen Krishna Chatradhi 

Regards,
Naveenk

-Original Message-
From: David Arcari  
Sent: Thursday, January 7, 2021 8:17 PM
To: linux-hw...@vger.kernel.org
Cc: David Arcari ; Chatradhi, Naveen Krishna 
; Jean Delvare ; Guenter 
Roeck ; linux-kernel@vger.kernel.org; sta...@vger.kernel.org
Subject: [PATCH] hwmon: (amd_energy) fix allocation of hwmon_channel_info config

[CAUTION: External Email]

hwmon, specifically hwmon_num_channel_attrs, expects the config array in the 
hwmon_channel_info structure to be terminated by a zero entry.  amd_energy does 
not honor this convention.  As result, a KASAN warning is possible.  Fix this 
by adding an additional entry and setting it to zero.

Fixes: 8abee9566b7e ("hwmon: Add amd_energy driver to report energy counters")

Signed-off-by: David Arcari 
Cc: Naveen Krishna Chatradhi 
[naveenk:] Signed-off-by: Naveen Krishna Chatradhi 
Cc: Jean Delvare 
Cc: Guenter Roeck 
Cc: linux-kernel@vger.kernel.org
Cc: sta...@vger.kernel.org
---
 drivers/hwmon/amd_energy.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/amd_energy.c b/drivers/hwmon/amd_energy.c index 
9b306448b7a0..822c2e74b98d 100644
--- a/drivers/hwmon/amd_energy.c
+++ b/drivers/hwmon/amd_energy.c
@@ -222,7 +222,7 @@ static int amd_create_sensor(struct device *dev,
 */
cpus = num_present_cpus() / num_siblings;

-   s_config = devm_kcalloc(dev, cpus + sockets,
+   s_config = devm_kcalloc(dev, cpus + sockets + 1,
sizeof(u32), GFP_KERNEL);
if (!s_config)
return -ENOMEM;
@@ -254,6 +254,7 @@ static int amd_create_sensor(struct device *dev,
scnprintf(label_l[i], 10, "Esocket%u", (i - cpus));
}

+   s_config[i] = 0;
return 0;
 }

--
2.18.1


RE: [PATCH linux hwmon-next v4 1/3] hwmon: (sbtsi) Add basic support for SB-TSI sensors

2020-12-03 Thread Chatradhi, Naveen Krishna
[AMD Official Use Only - Approved for External Use]

Hi Kun Yi,

> Test status: tested reading temp1_input, and reading/writing 
> temp1_max/min.

Tested the above at our end from an arm based BMC connected to the 2P Rome 
machine, it works fine. 

Regards,
Naveenk

-Original Message-
From: Guenter Roeck  
Sent: Thursday, December 3, 2020 7:08 AM
To: Kun Yi 
Cc: jdelv...@suse.com; robh...@kernel.org; mark.rutl...@arm.com; Venkatesh, 
Supreeth ; open...@lists.ozlabs.org; 
linux-hw...@vger.kernel.org; devicet...@vger.kernel.org; 
linux-kernel@vger.kernel.org
Subject: Re: [PATCH linux hwmon-next v4 1/3] hwmon: (sbtsi) Add basic support 
for SB-TSI sensors

[CAUTION: External Email]

On Wed, Dec 02, 2020 at 08:55:59AM -0800, Kun Yi wrote:
> SB Temperature Sensor Interface (SB-TSI) is an SMBus compatible 
> interface that reports AMD SoC's Ttcl (normalized temperature), and 
> resembles a typical 8-pin remote temperature sensor's I2C interface to 
> BMC.
>
> This commit adds basic support using this interface to read CPU 
> temperature, and read/write high/low CPU temp thresholds.
>
> To instantiate this driver on an AMD CPU with SB-TSI support, the i2c 
> bus number would be the bus connected from the board management 
> controller (BMC) to the CPU. The i2c address is specified in Section 
> 6.3.1 of the spec [1]: The SB-TSI address is normally 98h for socket 0 
> and 90h for socket 1, but it could vary based on hardware address 
> select pins.
>
> [1]: 
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.
> amd.com%2Fsystem%2Ffiles%2FTechDocs%2F56255_OSRR.pdfdata=04%7C01%
> 7CNaveenKrishna.Chatradhi%40amd.com%7C1a8cb0ebe4bb43bc759808d8972c562f
> %7C3dd8961fe4884e608e11a82d994e183d%7C0%7C1%7C637425563976853035%7CUnk
> nown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWw
> iLCJXVCI6Mn0%3D%7C1000sdata=oH5YmE000EUVGVxruzI%2FBRnWOKptlG%2Bpf
> yKferIwYME%3Dreserved=0
>
> Test status: tested reading temp1_input, and reading/writing 
> temp1_max/min.
>
> Signed-off-by: Kun Yi 
> ---
>  drivers/hwmon/Kconfig  |  10 ++
>  drivers/hwmon/Makefile |   1 +
>  drivers/hwmon/sbtsi_temp.c | 265 
> +
>  3 files changed, 276 insertions(+)
>  create mode 100644 drivers/hwmon/sbtsi_temp.c
>
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 
> 3c059fc23cd6..3d6a809700ae 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -1522,6 +1522,16 @@ config SENSORS_SL28CPLD
> This driver can also be built as a module.  If so, the module
> will be called sl28cpld-hwmon.
>
> +config SENSORS_SBTSI
> + tristate "Emulated SB-TSI temperature sensor"
> + depends on I2C
> + help
> +   If you say yes here you get support for emulated temperature
> +   sensors on AMD SoCs with SB-TSI interface connected to a BMC device.
> +
> +   This driver can also be built as a module. If so, the module will
> +   be called sbtsi_temp.
> +
>  config SENSORS_SHT15
>   tristate "Sensiron humidity and temperature sensors. SHT15 and compat."
>   depends on GPIOLIB || COMPILE_TEST diff --git 
> a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index 
> 01ca5d3fbad4..ee8c037919da 100644
> --- a/drivers/hwmon/Makefile
> +++ b/drivers/hwmon/Makefile
> @@ -160,6 +160,7 @@ obj-$(CONFIG_SENSORS_POWR1220)  += powr1220.o
>  obj-$(CONFIG_SENSORS_PWM_FAN)+= pwm-fan.o
>  obj-$(CONFIG_SENSORS_RASPBERRYPI_HWMON)  += raspberrypi-hwmon.o
>  obj-$(CONFIG_SENSORS_S3C)+= s3c-hwmon.o
> +obj-$(CONFIG_SENSORS_SBTSI)  += sbtsi_temp.o
>  obj-$(CONFIG_SENSORS_SCH56XX_COMMON)+= sch56xx-common.o
>  obj-$(CONFIG_SENSORS_SCH5627)+= sch5627.o
>  obj-$(CONFIG_SENSORS_SCH5636)+= sch5636.o
> diff --git a/drivers/hwmon/sbtsi_temp.c b/drivers/hwmon/sbtsi_temp.c 
> new file mode 100644 index ..6b0a7b9df1f3
> --- /dev/null
> +++ b/drivers/hwmon/sbtsi_temp.c
> @@ -0,0 +1,265 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * sbtsi_temp.c - hwmon driver for a SBI Temperature Sensor Interface 
> (SB-TSI)
> + *compliant AMD SoC temperature device.
> + *
> + * Copyright (c) 2020, Google Inc.
> + * Copyright (c) 2020, Kun Yi   */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/*
> + * SB-TSI registers only support SMBus byte data access. "_INT" 
> +registers are
> + * the integer part of a temperature value or limit, and "_DEC" 
> +registers are
> + * corresponding decimal parts.
> + */
> +#define SBTSI_REG_TEMP_INT   0x01 /* RO */
> +#define SBTSI_REG_STATUS 0x02 /* RO */
> +#define SBTSI_REG_CONFIG 0x03 /* RO */
> +#define SBTSI_REG_TEMP_HIGH_INT  0x07 /* RW */
> +#define SBTSI_REG_TEMP_LOW_INT   0x08 /* RW */
> +#define SBTSI_REG_TEMP_DEC   0x10 /* RW */
> +#define SBTSI_REG_TEMP_HIGH_DEC  0x13 /* RW */
> +#define