* [PATCH] platform/mellanox: mlxbf-pmc: fix sscanf() error checking
@ 2023-05-15 10:32 Dan Carpenter
2023-05-15 12:37 ` Ilpo Järvinen
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2023-05-15 10:32 UTC (permalink / raw)
To: Shravan Kumar Ramani
Cc: Hans de Goede, Mark Gross, Vadim Pasternak, Jiri Pirko,
platform-driver-x86, kernel-janitors
The sscanf() function never returns negatives. It returns the number of
items successfully read.
Fixes: 1a218d312e65 ("platform/mellanox: mlxbf-pmc: Add Mellanox BlueField PMC driver")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
drivers/platform/mellanox/mlxbf-pmc.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/platform/mellanox/mlxbf-pmc.c b/drivers/platform/mellanox/mlxbf-pmc.c
index c2c9b0d3244c..be967d797c28 100644
--- a/drivers/platform/mellanox/mlxbf-pmc.c
+++ b/drivers/platform/mellanox/mlxbf-pmc.c
@@ -1348,9 +1348,8 @@ static int mlxbf_pmc_map_counters(struct device *dev)
for (i = 0; i < pmc->total_blocks; ++i) {
if (strstr(pmc->block_name[i], "tile")) {
- ret = sscanf(pmc->block_name[i], "tile%d", &tile_num);
- if (ret < 0)
- return ret;
+ if (sscanf(pmc->block_name[i], "tile%d", &tile_num) != 1)
+ return -EINVAL;
if (tile_num >= pmc->tile_count)
continue;
--
2.39.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] platform/mellanox: mlxbf-pmc: fix sscanf() error checking
2023-05-15 10:32 [PATCH] platform/mellanox: mlxbf-pmc: fix sscanf() error checking Dan Carpenter
@ 2023-05-15 12:37 ` Ilpo Järvinen
2023-05-15 12:59 ` Hans de Goede
0 siblings, 1 reply; 3+ messages in thread
From: Ilpo Järvinen @ 2023-05-15 12:37 UTC (permalink / raw)
To: Dan Carpenter
Cc: Shravan Kumar Ramani, Hans de Goede, Mark Gross, Vadim Pasternak,
Jiri Pirko, platform-driver-x86, kernel-janitors
[-- Attachment #1: Type: text/plain, Size: 1125 bytes --]
On Mon, 15 May 2023, Dan Carpenter wrote:
> The sscanf() function never returns negatives. It returns the number of
> items successfully read.
>
> Fixes: 1a218d312e65 ("platform/mellanox: mlxbf-pmc: Add Mellanox BlueField PMC driver")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> drivers/platform/mellanox/mlxbf-pmc.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/platform/mellanox/mlxbf-pmc.c b/drivers/platform/mellanox/mlxbf-pmc.c
> index c2c9b0d3244c..be967d797c28 100644
> --- a/drivers/platform/mellanox/mlxbf-pmc.c
> +++ b/drivers/platform/mellanox/mlxbf-pmc.c
> @@ -1348,9 +1348,8 @@ static int mlxbf_pmc_map_counters(struct device *dev)
>
> for (i = 0; i < pmc->total_blocks; ++i) {
> if (strstr(pmc->block_name[i], "tile")) {
> - ret = sscanf(pmc->block_name[i], "tile%d", &tile_num);
> - if (ret < 0)
> - return ret;
> + if (sscanf(pmc->block_name[i], "tile%d", &tile_num) != 1)
> + return -EINVAL;
>
> if (tile_num >= pmc->tile_count)
> continue;
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
--
i.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] platform/mellanox: mlxbf-pmc: fix sscanf() error checking
2023-05-15 12:37 ` Ilpo Järvinen
@ 2023-05-15 12:59 ` Hans de Goede
0 siblings, 0 replies; 3+ messages in thread
From: Hans de Goede @ 2023-05-15 12:59 UTC (permalink / raw)
To: Ilpo Järvinen, Dan Carpenter
Cc: Shravan Kumar Ramani, Mark Gross, Vadim Pasternak, Jiri Pirko,
platform-driver-x86, kernel-janitors
Hi,
On 5/15/23 14:37, Ilpo Järvinen wrote:
> On Mon, 15 May 2023, Dan Carpenter wrote:
>
>> The sscanf() function never returns negatives. It returns the number of
>> items successfully read.
>>
>> Fixes: 1a218d312e65 ("platform/mellanox: mlxbf-pmc: Add Mellanox BlueField PMC driver")
>> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
>> ---
>> drivers/platform/mellanox/mlxbf-pmc.c | 5 ++---
>> 1 file changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/platform/mellanox/mlxbf-pmc.c b/drivers/platform/mellanox/mlxbf-pmc.c
>> index c2c9b0d3244c..be967d797c28 100644
>> --- a/drivers/platform/mellanox/mlxbf-pmc.c
>> +++ b/drivers/platform/mellanox/mlxbf-pmc.c
>> @@ -1348,9 +1348,8 @@ static int mlxbf_pmc_map_counters(struct device *dev)
>>
>> for (i = 0; i < pmc->total_blocks; ++i) {
>> if (strstr(pmc->block_name[i], "tile")) {
>> - ret = sscanf(pmc->block_name[i], "tile%d", &tile_num);
>> - if (ret < 0)
>> - return ret;
>> + if (sscanf(pmc->block_name[i], "tile%d", &tile_num) != 1)
>> + return -EINVAL;
>>
>> if (tile_num >= pmc->tile_count)
>> continue;
>
> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Thank you for your patch, I've applied this patch to my fixes
branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=fixes
Note it will show up in my fixes branch once I've pushed my
local branch there, which might take a while.
I will include this patch in my next fixes pull-req to Linus
for the current kernel development cycle.
Regards,
Hans
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-05-15 13:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-15 10:32 [PATCH] platform/mellanox: mlxbf-pmc: fix sscanf() error checking Dan Carpenter
2023-05-15 12:37 ` Ilpo Järvinen
2023-05-15 12:59 ` Hans de Goede
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox