Skip to contentSkip to conversation

drivers: iio: proximity: This patch fix the following checkpatch warning.

PATCH In review Mohan Kumar 4 participants 5 messages Apr 17, 2019 – Apr 24, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: iio: proximity: This patch fix the following checkpatch warning.

As per Documentation/timers/timers-howto.txt Msleep < 20ms can sleep for up to 20ms. so use usleep_range.

---
 drivers/iio/proximity/mb1232.c | 2 +-
 drivers/iio/proximity/srf08.c  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/iio/proximity/mb1232.c +1 -1
index 166b3e6..74f7eae 100644
@@ -81,7 +81,7 @@ static s16 mb1232_read_distance(struct mb1232_data *data)
 		}
 	} else {
 		/* use simple sleep if announce irq is not connected */
-		msleep(15);
+		usleep_range(15000, 20000);
 	}
 
 	ret = i2c_master_recv(client, (char *)&buf, sizeof(buf));
drivers/iio/proximity/srf08.c +2 -2
index f2bf783..605a582 100644
@@ -150,7 +150,7 @@ static int srf08_read_ranging(struct srf08_data *data)
 	 * polling for not more than 20 ms should be enough
 	 */
 	waittime = 1 + data->range_mm / 172;
-	msleep(waittime);
+	usleep_range(waittime * 1000, (waittime * 1000) + 2000);
 	for (i = 0; i < 4; i++) {
 		ret = i2c_smbus_read_byte_data(data->client,
 						SRF08_READ_SW_REVISION);
@@ -158,7 +158,7 @@ static int srf08_read_ranging(struct srf08_data *data)
 		/* check if a valid version number is read */
 		if (ret < 255 && ret > 0)
 			break;
-		msleep(5);
+		usleep_range(5000, 15000);
 	}
 
 	if (ret >= 255 || ret <= 0) {
Signature · 1 line
2.7.4
#1 lore raw

See comments inline

Quoted 15 lines · Mohan Kumar

As per Documentation/timers/timers-howto.txt Msleep < 20ms can sleep for up to 20ms. so use usleep_range.

---
 drivers/iio/proximity/mb1232.c | 2 +-
 drivers/iio/proximity/srf08.c  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/iio/proximity/mb1232.c +0 -0
index 166b3e6..74f7eae 100644

drivers/iio/proximity/mb1232.c static s16 mb1232_read_distance(struct mb1232_data *data) · line 84

Quoted 5 lines
drivers/iio/proximity/mb1232.c +1 -1
@@ -81,7 +81,7 @@ static s16 mb1232_read_distance(struct mb1232_data *data)
                }
        } else {
                /* use simple sleep if announce irq is not connected */
-               msleep(15);
+               usleep_range(15000, 20000);

This is actually less than ideal.. because usleep_range uses the hrtimers which forces an interrupt.

Unless you actually need to read between 15ms and 20ms it is best just to leave the msleep() as it is, and let it take a bit longer if required.

- Matt

Quoted 28 lines
drivers/iio/proximity/mb1232.c +0 -0
        }
 
        ret = i2c_master_recv(client, (char *)&buf, sizeof(buf));
drivers/iio/proximity/srf08.c +2 -3
index f2bf783..605a582 100644
@@ -150,7 +150,7 @@ static int srf08_read_ranging(struct srf08_data *data)
         * polling for not more than 20 ms should be enough
         */
        waittime = 1 + data->range_mm / 172;
-       msleep(waittime);
+       usleep_range(waittime * 1000, (waittime * 1000) + 2000);
        for (i = 0; i < 4; i++) {
                ret = i2c_smbus_read_byte_data(data->client,
                                                SRF08_READ_SW_REVISION);
@@ -158,7 +158,7 @@ static int srf08_read_ranging(struct srf08_data *data)
                /* check if a valid version number is read */
                if (ret < 255 && ret > 0)
                        break;
-               msleep(5);
+               usleep_range(5000, 15000);
        }
 
        if (ret >= 255 || ret <= 0) {
--

2.7.4

maintainer
#2 lore raw
Quoted 27 lines · On Thu, 18 Apr 2019 16:23:51 -0700 Matt Ranostay <[email protected]>…

See comments inline

Quoted 15 lines · Mohan Kumar

As per Documentation/timers/timers-howto.txt Msleep < 20ms can sleep for up to 20ms. so use usleep_range.

---
 drivers/iio/proximity/mb1232.c | 2 +-
 drivers/iio/proximity/srf08.c  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/iio/proximity/mb1232.c +0 -0
index 166b3e6..74f7eae 100644

drivers/iio/proximity/mb1232.c static s16 mb1232_read_distance(struct mb1232_data *data) · line 84

Quoted 5 lines
drivers/iio/proximity/mb1232.c +1 -1
@@ -81,7 +81,7 @@ static s16 mb1232_read_distance(struct mb1232_data *data)
                }
        } else {
                /* use simple sleep if announce irq is not connected */
-               msleep(15);
+               usleep_range(15000, 20000);  

This is actually less than ideal.. because usleep_range uses the hrtimers which forces an interrupt.

Quoted 3 lines

Unless you actually need to read between 15ms and 20ms it is best just to leave the msleep() as it is, and let it take a bit longer if required.

Good response. Perhaps Mohan could follow up with a patch to add a comment to this effect to save anyone else trying to 'fix' this issue in future?

Thanks,

Jonathan

Quoted 31 lines

- Matt

Quoted 28 lines
drivers/iio/proximity/mb1232.c +0 -0
        }
 
        ret = i2c_master_recv(client, (char *)&buf, sizeof(buf));
drivers/iio/proximity/srf08.c +2 -3
index f2bf783..605a582 100644
@@ -150,7 +150,7 @@ static int srf08_read_ranging(struct srf08_data *data)
         * polling for not more than 20 ms should be enough
         */
        waittime = 1 + data->range_mm / 172;
-       msleep(waittime);
+       usleep_range(waittime * 1000, (waittime * 1000) + 2000);
        for (i = 0; i < 4; i++) {
                ret = i2c_smbus_read_byte_data(data->client,
                                                SRF08_READ_SW_REVISION);
@@ -158,7 +158,7 @@ static int srf08_read_ranging(struct srf08_data *data)
                /* check if a valid version number is read */
                if (ret < 255 && ret > 0)
                        break;
-               msleep(5);
+               usleep_range(5000, 15000);
        }
 
        if (ret >= 255 || ret <= 0) {
--

2.7.4

#3 lore raw
Quoted 31 lines · Jonathan Cameron
Quoted 27 lines · On Thu, 18 Apr 2019 16:23:51 -0700 Matt Ranostay <[email protected]>…

See comments inline

Quoted 15 lines · Mohan Kumar

As per Documentation/timers/timers-howto.txt Msleep < 20ms can sleep for up to 20ms. so use usleep_range.

---
 drivers/iio/proximity/mb1232.c | 2 +-
 drivers/iio/proximity/srf08.c  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/iio/proximity/mb1232.c +0 -0
index 166b3e6..74f7eae 100644

drivers/iio/proximity/mb1232.c static s16 mb1232_read_distance(struct mb1232_data *data) · line 84

Quoted 5 lines
drivers/iio/proximity/mb1232.c +1 -1
@@ -81,7 +81,7 @@ static s16 mb1232_read_distance(struct mb1232_data *data)
                }
        } else {
                /* use simple sleep if announce irq is not connected */
-               msleep(15);
+               usleep_range(15000, 20000);

This is actually less than ideal.. because usleep_range uses the hrtimers which forces an interrupt.

Quoted 6 lines
Quoted 3 lines

Unless you actually need to read between 15ms and 20ms it is best just to leave the msleep() as it is, and let it take a bit longer if required.

Good response. Perhaps Mohan could follow up with a patch to add a comment to this effect to save anyone else trying to 'fix' this issue in future?

Change of the warning message in the checkpatch.pl script you mean?

- Matt

Quoted 36 lines

Thanks,

Jonathan

Quoted 31 lines

- Matt

Quoted 28 lines
drivers/iio/proximity/mb1232.c +0 -0
        }
 
        ret = i2c_master_recv(client, (char *)&buf, sizeof(buf));
drivers/iio/proximity/srf08.c +2 -3
index f2bf783..605a582 100644
@@ -150,7 +150,7 @@ static int srf08_read_ranging(struct srf08_data *data)
         * polling for not more than 20 ms should be enough
         */
        waittime = 1 + data->range_mm / 172;
-       msleep(waittime);
+       usleep_range(waittime * 1000, (waittime * 1000) + 2000);
        for (i = 0; i < 4; i++) {
                ret = i2c_smbus_read_byte_data(data->client,
                                                SRF08_READ_SW_REVISION);
@@ -158,7 +158,7 @@ static int srf08_read_ranging(struct srf08_data *data)
                /* check if a valid version number is read */
                if (ret < 255 && ret > 0)
                        break;
-               msleep(5);
+               usleep_range(5000, 15000);
        }
 
        if (ret >= 255 || ret <= 0) {
--

2.7.4

#4 lore raw
Quoted 32 lines · On Wed, 24 Apr 2019 17:23:26 +0800 Matt Ranostay <[email protected]>…
Quoted 31 lines · Jonathan Cameron
Quoted 27 lines · On Thu, 18 Apr 2019 16:23:51 -0700 Matt Ranostay <[email protected]>…

See comments inline

Quoted 15 lines · Mohan Kumar

As per Documentation/timers/timers-howto.txt Msleep < 20ms can sleep for up to 20ms. so use usleep_range.

---
 drivers/iio/proximity/mb1232.c | 2 +-
 drivers/iio/proximity/srf08.c  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/iio/proximity/mb1232.c +0 -0
index 166b3e6..74f7eae 100644

drivers/iio/proximity/mb1232.c static s16 mb1232_read_distance(struct mb1232_data *data) · line 84

Quoted 5 lines
drivers/iio/proximity/mb1232.c +1 -1
@@ -81,7 +81,7 @@ static s16 mb1232_read_distance(struct mb1232_data *data)
                }
        } else {
                /* use simple sleep if announce irq is not connected */
-               msleep(15);
+               usleep_range(15000, 20000);  

This is actually less than ideal.. because usleep_range uses the hrtimers which forces an interrupt.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Unless you actually need to read between 15ms and 20ms it is best just to leave the msleep() as it is, and let it take a bit longer if required.

Good response. Perhaps Mohan could follow up with a patch to add a comment to this effect to save anyone else trying to 'fix' this issue in future?

Change of the warning message in the checkpatch.pl script you mean?

No. That's basically telling people to 'think about it'. I meant a comment in the source for this driver to say 'We don't care here because...'.

That way anyone preparing a patch for this in future will see the comment and not bother.

Jonathan

Quoted 39 lines

- Matt

Quoted 36 lines

Thanks,

Jonathan

Quoted 31 lines

- Matt

Quoted 28 lines
drivers/iio/proximity/mb1232.c +0 -0
        }
 
        ret = i2c_master_recv(client, (char *)&buf, sizeof(buf));
drivers/iio/proximity/srf08.c +2 -3
index f2bf783..605a582 100644
@@ -150,7 +150,7 @@ static int srf08_read_ranging(struct srf08_data *data)
         * polling for not more than 20 ms should be enough
         */
        waittime = 1 + data->range_mm / 172;
-       msleep(waittime);
+       usleep_range(waittime * 1000, (waittime * 1000) + 2000);
        for (i = 0; i < 4; i++) {
                ret = i2c_smbus_read_byte_data(data->client,
                                                SRF08_READ_SW_REVISION);
@@ -158,7 +158,7 @@ static int srf08_read_ranging(struct srf08_data *data)
                /* check if a valid version number is read */
                if (ret < 255 && ret > 0)
                        break;
-               msleep(5);
+               usleep_range(5000, 15000);
        }
 
        if (ret >= 255 || ret <= 0) {
--

2.7.4