All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH platform 0/2] platform/mellanox: Fixes for register space access
@ 2021-09-27 14:22 Vadim Pasternak
  2021-09-27 14:22 ` [PATCH platform 1/2] platform/mellanox: mlxreg-io: Fix argument base in kstrtou32() call Vadim Pasternak
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Vadim Pasternak @ 2021-09-27 14:22 UTC (permalink / raw)
  To: hdegoede; +Cc: platform-driver-x86, Vadim Pasternak

Patch set contains:
Patch #1 - Fix argument for kstrtou32() conversion.
Patch #2 - Fix rea access for complex attribute.

Vadim Pasternak (2):
  platform/mellanox: mlxreg-io: Fix argument base in kstrtou32() call
  platform/mellanox: mlxreg-io: Fix read access of n-bytes size
    attributes

 drivers/platform/mellanox/mlxreg-io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH platform 1/2] platform/mellanox: mlxreg-io: Fix argument base in kstrtou32() call
  2021-09-27 14:22 [PATCH platform 0/2] platform/mellanox: Fixes for register space access Vadim Pasternak
@ 2021-09-27 14:22 ` Vadim Pasternak
  2021-09-27 14:22 ` [PATCH platform 2/2] platform/mellanox: mlxreg-io: Fix read access of n-bytes size attributes Vadim Pasternak
  2021-10-11 12:56 ` [PATCH platform 0/2] platform/mellanox: Fixes for register space access Hans de Goede
  2 siblings, 0 replies; 4+ messages in thread
From: Vadim Pasternak @ 2021-09-27 14:22 UTC (permalink / raw)
  To: hdegoede; +Cc: platform-driver-x86, Vadim Pasternak

Change kstrtou32() argument 'base' to be zero instead of 'len'.
It works by chance for setting one bit value, but it is not supposed to
work in case value passed to mlxreg_io_attr_store() is greater than 1.

It works for example, for:
echo 1 > /sys/devices/platform/mlxplat/mlxreg-io/hwmon/.../jtag_enable
But it will fail for:
echo n > /sys/devices/platform/mlxplat/mlxreg-io/hwmon/.../jtag_enable,
where n > 1.

The flow for input buffer conversion is as below:
_kstrtoull(const char *s, unsigned int base, unsigned long long *res)
calls:
rv = _parse_integer(s, base, &_res);

For the second case, where n > 1:
- _parse_integer() converts 's' to 'val'.
  For n=2, 'len' is set to 2 (string buffer is 0x32 0x0a), for n=3
  'len' is set to 3 (string buffer 0x33 0x0a), etcetera.
- 'base' is equal or greater then '2' (length of input buffer).

As a result, _parse_integer() exits with result zero (rv):
	rv = 0;
	while (1) {
		...
		if (val >= base)-> (2 >= 2)
			break;
		...
		rv++;
		...
	}

And _kstrtoull() in their turn will fail:
	if (rv == 0)
		return -EINVAL;

Fixes: 5ec4a8ace06c ("platform/mellanox: Introduce support for Mellanox register access driver")
Signed-off-by: Vadim Pasternak <vadimp@nvidia.com>
---
 drivers/platform/mellanox/mlxreg-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/mellanox/mlxreg-io.c b/drivers/platform/mellanox/mlxreg-io.c
index 7646708d57e4..a023ec02126b 100644
--- a/drivers/platform/mellanox/mlxreg-io.c
+++ b/drivers/platform/mellanox/mlxreg-io.c
@@ -141,7 +141,7 @@ mlxreg_io_attr_store(struct device *dev, struct device_attribute *attr,
 		return -EINVAL;
 
 	/* Convert buffer to input value. */
-	ret = kstrtou32(buf, len, &input_val);
+	ret = kstrtou32(buf, 0, &input_val);
 	if (ret)
 		return ret;
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH platform 2/2] platform/mellanox: mlxreg-io: Fix read access of n-bytes size attributes
  2021-09-27 14:22 [PATCH platform 0/2] platform/mellanox: Fixes for register space access Vadim Pasternak
  2021-09-27 14:22 ` [PATCH platform 1/2] platform/mellanox: mlxreg-io: Fix argument base in kstrtou32() call Vadim Pasternak
@ 2021-09-27 14:22 ` Vadim Pasternak
  2021-10-11 12:56 ` [PATCH platform 0/2] platform/mellanox: Fixes for register space access Hans de Goede
  2 siblings, 0 replies; 4+ messages in thread
From: Vadim Pasternak @ 2021-09-27 14:22 UTC (permalink / raw)
  To: hdegoede; +Cc: platform-driver-x86, Vadim Pasternak

Fix shift argument for function rol32(). It should be provided in bits,
while was provided in bytes.

Fixes: 86148190a7db ("platform/mellanox: mlxreg-io: Add support for complex attributes")
Signed-off-by: Vadim Pasternak <vadimp@nvidia.com>
---
 drivers/platform/mellanox/mlxreg-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/mellanox/mlxreg-io.c b/drivers/platform/mellanox/mlxreg-io.c
index a023ec02126b..a916cd89cbbe 100644
--- a/drivers/platform/mellanox/mlxreg-io.c
+++ b/drivers/platform/mellanox/mlxreg-io.c
@@ -98,7 +98,7 @@ mlxreg_io_get_reg(void *regmap, struct mlxreg_core_data *data, u32 in_val,
 			if (ret)
 				goto access_error;
 
-			*regval |= rol32(val, regsize * i);
+			*regval |= rol32(val, regsize * i * 8);
 		}
 	}
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH platform 0/2] platform/mellanox: Fixes for register space access
  2021-09-27 14:22 [PATCH platform 0/2] platform/mellanox: Fixes for register space access Vadim Pasternak
  2021-09-27 14:22 ` [PATCH platform 1/2] platform/mellanox: mlxreg-io: Fix argument base in kstrtou32() call Vadim Pasternak
  2021-09-27 14:22 ` [PATCH platform 2/2] platform/mellanox: mlxreg-io: Fix read access of n-bytes size attributes Vadim Pasternak
@ 2021-10-11 12:56 ` Hans de Goede
  2 siblings, 0 replies; 4+ messages in thread
From: Hans de Goede @ 2021-10-11 12:56 UTC (permalink / raw)
  To: Vadim Pasternak; +Cc: platform-driver-x86

Hi,

On 9/27/21 4:22 PM, Vadim Pasternak wrote:
> Patch set contains:
> Patch #1 - Fix argument for kstrtou32() conversion.
> Patch #2 - Fix rea access for complex attribute.

Thank you for your patch-series, I've applied the series to my
review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Note it will show up in my review-hans branch once I've pushed my
local branch there, which might take a while.

Since these are both clear bug fixes I will also include these
in my upcoming pdx86-fixes pull-req for 5.15 .

Once I've run some tests on this branch the patches there will be
added to the platform-drivers-x86/for-next branch and eventually
will be included in the pdx86 pull-request to Linus for the next
merge-window.

Regards,

Hans


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-10-11 12:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-27 14:22 [PATCH platform 0/2] platform/mellanox: Fixes for register space access Vadim Pasternak
2021-09-27 14:22 ` [PATCH platform 1/2] platform/mellanox: mlxreg-io: Fix argument base in kstrtou32() call Vadim Pasternak
2021-09-27 14:22 ` [PATCH platform 2/2] platform/mellanox: mlxreg-io: Fix read access of n-bytes size attributes Vadim Pasternak
2021-10-11 12:56 ` [PATCH platform 0/2] platform/mellanox: Fixes for register space access Hans de Goede

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.