[PATCH 1/4] w1: ds1wm: Fix check for resource size

From: Julian Haller
Date: Thu Jun 30 2022 - 07:27:04 EST


From: Julian Haller <julian.haller@xxxxxxxxxxx>

Commit 242b476f821b ("w1: ds1wm: fix register offset (bus shift)
calculation") introduced a check for the minimum resource size to span
at least 8 registers. However, the DS1WM only has 6 registers:

DS1WM_CMD 0x00 /* R/W 4 bits command */
DS1WM_DATA 0x01 /* R/W 8 bits, transmit/receive buffer */
DS1WM_INT 0x02 /* R/W interrupt status */
DS1WM_INT_EN 0x03 /* R/W interrupt enable */
DS1WM_CLKDIV 0x04 /* R/W 5 bits of divisor and pre-scale */
DS1WM_CNTRL 0x05 /* R/W master control register */

This causes the probe to fail incorrectly when the actual resource size of
6 is specified instead of 8.

Fixes: 242b476f821b ("w1: ds1wm: fix register offset (bus shift) calculation")
Signed-off-by: Julian Haller <julian.haller@xxxxxxxxxxx>
---
drivers/w1/masters/ds1wm.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/w1/masters/ds1wm.c b/drivers/w1/masters/ds1wm.c
index f661695fb589..0ecb14772f30 100644
--- a/drivers/w1/masters/ds1wm.c
+++ b/drivers/w1/masters/ds1wm.c
@@ -544,13 +544,12 @@ static int ds1wm_probe(struct platform_device *pdev)
return -EINVAL;
}

- ds1wm_data->bus_shift = plat->bus_shift;
- /* make sure resource has space for 8 registers */
- if ((8 << ds1wm_data->bus_shift) > resource_size(res)) {
+ /* make sure resource has space for 6 registers */
+ if ((6 << ds1wm_data->bus_shift) > resource_size(res)) {
dev_err(&ds1wm_data->pdev->dev,
"memory resource size %d to small, should be %d\n",
(int)resource_size(res),
- 8 << ds1wm_data->bus_shift);
+ 6 << ds1wm_data->bus_shift);
return -EINVAL;
}

--
2.25.1