linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] staging:iio:ad2s90: Add scale info and improve error handling
@ 2018-10-26  0:45 Matheus Tavares
  2018-10-26  0:45 ` [PATCH 1/6] staging:iio:ad2s90: Make read_raw return spi_read's error code Matheus Tavares
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Matheus Tavares @ 2018-10-26  0:45 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Hartmut Knaack, Peter Meerwald-Stadler, Greg Kroah-Hartman
  Cc: linux-iio, devel, linux-kernel, kernel-usp

This patch set adds scale info to ad2s90's single channel, improve
error handling in it's functions and fix a possible race condition
issue.

The goal with this patch set is to address the points discussed in the
mailing list in an effort to move ad2s90.c out of staging.

Matheus Tavares (5):
  staging:iio:ad2s90: Make read_raw return spi_read's error code
  staging:iio:ad2s90: Make probe handle spi_setup failure
  staging:iio:ad2s90: Remove always overwritten assignment
  staging:iio:ad2s90: Move device registration to the end of probe
  staging:iio:ad2s90: Check channel type at read_raw

Victor Colombo (1):
  staging:iio:ad2s90: Add IIO_CHAN_INFO_SCALE to channel spec and
    read_raw

 drivers/staging/iio/resolver/ad2s90.c | 55 ++++++++++++++++++---------
 1 file changed, 37 insertions(+), 18 deletions(-)

-- 
2.18.0


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

* [PATCH 1/6] staging:iio:ad2s90: Make read_raw return spi_read's error code
  2018-10-26  0:45 [PATCH 0/6] staging:iio:ad2s90: Add scale info and improve error handling Matheus Tavares
@ 2018-10-26  0:45 ` Matheus Tavares
  2018-10-26  0:45 ` [PATCH 2/6] staging:iio:ad2s90: Make probe handle spi_setup failure Matheus Tavares
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Matheus Tavares @ 2018-10-26  0:45 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Hartmut Knaack, Peter Meerwald-Stadler, Greg Kroah-Hartman
  Cc: linux-iio, devel, linux-kernel, kernel-usp

Previously, when spi_read returned an error code inside ad2s90_read_raw,
the code was ignored and IIO_VAL_INT was returned. This patch makes the
function return the error code returned by spi_read when it fails.

Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
---
 drivers/staging/iio/resolver/ad2s90.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/iio/resolver/ad2s90.c b/drivers/staging/iio/resolver/ad2s90.c
index 59586947a936..11fac9f90148 100644
--- a/drivers/staging/iio/resolver/ad2s90.c
+++ b/drivers/staging/iio/resolver/ad2s90.c
@@ -35,12 +35,15 @@ static int ad2s90_read_raw(struct iio_dev *indio_dev,
 	struct ad2s90_state *st = iio_priv(indio_dev);
 
 	mutex_lock(&st->lock);
+
 	ret = spi_read(st->sdev, st->rx, 2);
-	if (ret)
-		goto error_ret;
+	if (ret < 0) {
+		mutex_unlock(&st->lock);
+		return ret;
+	}
+
 	*val = (((u16)(st->rx[0])) << 4) | ((st->rx[1] & 0xF0) >> 4);
 
-error_ret:
 	mutex_unlock(&st->lock);
 
 	return IIO_VAL_INT;
-- 
2.18.0


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

* [PATCH 2/6] staging:iio:ad2s90: Make probe handle spi_setup failure
  2018-10-26  0:45 [PATCH 0/6] staging:iio:ad2s90: Add scale info and improve error handling Matheus Tavares
  2018-10-26  0:45 ` [PATCH 1/6] staging:iio:ad2s90: Make read_raw return spi_read's error code Matheus Tavares
@ 2018-10-26  0:45 ` Matheus Tavares
  2018-10-26  0:45 ` [PATCH 3/6] staging:iio:ad2s90: Remove always overwritten assignment Matheus Tavares
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Matheus Tavares @ 2018-10-26  0:45 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Hartmut Knaack, Peter Meerwald-Stadler, Greg Kroah-Hartman
  Cc: linux-iio, devel, linux-kernel, kernel-usp

Previously, ad2s90_probe ignored the return code from spi_setup, not
handling its possible failure. This patch makes ad2s90_probe check if
the code is an error code and, if so, do the following:

- Call dev_err with an appropriate error message.
- Return the spi_setup's error code, aborting the execution of the
rest of the function.

Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
---
 drivers/staging/iio/resolver/ad2s90.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/iio/resolver/ad2s90.c b/drivers/staging/iio/resolver/ad2s90.c
index 11fac9f90148..d6a42e3f1bd8 100644
--- a/drivers/staging/iio/resolver/ad2s90.c
+++ b/drivers/staging/iio/resolver/ad2s90.c
@@ -88,7 +88,12 @@ static int ad2s90_probe(struct spi_device *spi)
 	/* need 600ns between CS and the first falling edge of SCLK */
 	spi->max_speed_hz = 830000;
 	spi->mode = SPI_MODE_3;
-	spi_setup(spi);
+	ret = spi_setup(spi);
+
+	if (ret < 0) {
+		dev_err(&spi->dev, "spi_setup failed!\n");
+		return ret;
+	}
 
 	return 0;
 }
-- 
2.18.0


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

* [PATCH 3/6] staging:iio:ad2s90: Remove always overwritten assignment
  2018-10-26  0:45 [PATCH 0/6] staging:iio:ad2s90: Add scale info and improve error handling Matheus Tavares
  2018-10-26  0:45 ` [PATCH 1/6] staging:iio:ad2s90: Make read_raw return spi_read's error code Matheus Tavares
  2018-10-26  0:45 ` [PATCH 2/6] staging:iio:ad2s90: Make probe handle spi_setup failure Matheus Tavares
@ 2018-10-26  0:45 ` Matheus Tavares
  2018-10-26  0:45 ` [PATCH 4/6] staging:iio:ad2s90: Move device registration to the end of probe Matheus Tavares
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Matheus Tavares @ 2018-10-26  0:45 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Hartmut Knaack, Peter Meerwald-Stadler, Greg Kroah-Hartman
  Cc: linux-iio, devel, linux-kernel, kernel-usp

This patch removes an initial assignment to the variable ret at probe,
that was always overwritten.

Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
---
 drivers/staging/iio/resolver/ad2s90.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/iio/resolver/ad2s90.c b/drivers/staging/iio/resolver/ad2s90.c
index d6a42e3f1bd8..c20d37dc065a 100644
--- a/drivers/staging/iio/resolver/ad2s90.c
+++ b/drivers/staging/iio/resolver/ad2s90.c
@@ -64,7 +64,7 @@ static int ad2s90_probe(struct spi_device *spi)
 {
 	struct iio_dev *indio_dev;
 	struct ad2s90_state *st;
-	int ret = 0;
+	int ret;
 
 	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
 	if (!indio_dev)
-- 
2.18.0


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

* [PATCH 4/6] staging:iio:ad2s90: Move device registration to the end of probe
  2018-10-26  0:45 [PATCH 0/6] staging:iio:ad2s90: Add scale info and improve error handling Matheus Tavares
                   ` (2 preceding siblings ...)
  2018-10-26  0:45 ` [PATCH 3/6] staging:iio:ad2s90: Remove always overwritten assignment Matheus Tavares
@ 2018-10-26  0:45 ` Matheus Tavares
  2018-10-26  0:45 ` [PATCH 5/6] staging:iio:ad2s90: Add IIO_CHAN_INFO_SCALE to channel spec and read_raw Matheus Tavares
  2018-10-26  0:45 ` [PATCH 6/6] staging:iio:ad2s90: Check channel type at read_raw Matheus Tavares
  5 siblings, 0 replies; 9+ messages in thread
From: Matheus Tavares @ 2018-10-26  0:45 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Hartmut Knaack, Peter Meerwald-Stadler, Greg Kroah-Hartman
  Cc: linux-iio, devel, linux-kernel, kernel-usp

Previously, devm_iio_device_register was being called before the
spi_setup call and the spi_device's max_speed_hz and mode assignments.
This could lead to a race condition since the driver was still being
set up after it was already made ready to use. To fix it, this patch
moves the device registration to the end of ad2s90_probe.

Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
---
 drivers/staging/iio/resolver/ad2s90.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/staging/iio/resolver/ad2s90.c b/drivers/staging/iio/resolver/ad2s90.c
index c20d37dc065a..b4a6a89c11b0 100644
--- a/drivers/staging/iio/resolver/ad2s90.c
+++ b/drivers/staging/iio/resolver/ad2s90.c
@@ -81,10 +81,6 @@ static int ad2s90_probe(struct spi_device *spi)
 	indio_dev->num_channels = 1;
 	indio_dev->name = spi_get_device_id(spi)->name;
 
-	ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev);
-	if (ret)
-		return ret;
-
 	/* need 600ns between CS and the first falling edge of SCLK */
 	spi->max_speed_hz = 830000;
 	spi->mode = SPI_MODE_3;
@@ -95,7 +91,7 @@ static int ad2s90_probe(struct spi_device *spi)
 		return ret;
 	}
 
-	return 0;
+	return devm_iio_device_register(indio_dev->dev.parent, indio_dev);
 }
 
 static const struct spi_device_id ad2s90_id[] = {
-- 
2.18.0


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

* [PATCH 5/6] staging:iio:ad2s90: Add IIO_CHAN_INFO_SCALE to channel spec and read_raw
  2018-10-26  0:45 [PATCH 0/6] staging:iio:ad2s90: Add scale info and improve error handling Matheus Tavares
                   ` (3 preceding siblings ...)
  2018-10-26  0:45 ` [PATCH 4/6] staging:iio:ad2s90: Move device registration to the end of probe Matheus Tavares
@ 2018-10-26  0:45 ` Matheus Tavares
  2018-10-26 10:04   ` Dan Carpenter
  2018-10-26  0:45 ` [PATCH 6/6] staging:iio:ad2s90: Check channel type at read_raw Matheus Tavares
  5 siblings, 1 reply; 9+ messages in thread
From: Matheus Tavares @ 2018-10-26  0:45 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Hartmut Knaack, Peter Meerwald-Stadler, Greg Kroah-Hartman
  Cc: linux-iio, devel, linux-kernel, kernel-usp, Victor Colombo

From: Victor Colombo <victorcolombo@gmail.com>

This patch adds the IIO_CHAN_INFO_SCALE mask to ad2s90_chan and
implements the relative read behavior at ad2s90_read_raw.

Signed-off-by: Victor Colombo <victorcolombo@gmail.com>
---
 drivers/staging/iio/resolver/ad2s90.c | 32 ++++++++++++++++++---------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/iio/resolver/ad2s90.c b/drivers/staging/iio/resolver/ad2s90.c
index b4a6a89c11b0..52b656875ed1 100644
--- a/drivers/staging/iio/resolver/ad2s90.c
+++ b/drivers/staging/iio/resolver/ad2s90.c
@@ -34,19 +34,31 @@ static int ad2s90_read_raw(struct iio_dev *indio_dev,
 	int ret;
 	struct ad2s90_state *st = iio_priv(indio_dev);
 
-	mutex_lock(&st->lock);
+	switch (m) {
+	case IIO_CHAN_INFO_SCALE:
+		/* 2 * Pi / (2^12 - 1) ~= 0.001534355 */
+		*val = 0;
+		*val2 = 1534355;
+		return IIO_VAL_INT_PLUS_NANO;
+	case IIO_CHAN_INFO_RAW:
+		mutex_lock(&st->lock);
+
+		ret = spi_read(st->sdev, st->rx, 2);
+		if (ret < 0) {
+			mutex_unlock(&st->lock);
+			return ret;
+		}
+
+		*val = (((u16)(st->rx[0])) << 4) | ((st->rx[1] & 0xF0) >> 4);
 
-	ret = spi_read(st->sdev, st->rx, 2);
-	if (ret < 0) {
 		mutex_unlock(&st->lock);
-		return ret;
-	}
 
-	*val = (((u16)(st->rx[0])) << 4) | ((st->rx[1] & 0xF0) >> 4);
-
-	mutex_unlock(&st->lock);
+		return IIO_VAL_INT;
+	default:
+		break;
+	}
 
-	return IIO_VAL_INT;
+	return -EINVAL;
 }
 
 static const struct iio_info ad2s90_info = {
@@ -57,7 +69,7 @@ static const struct iio_chan_spec ad2s90_chan = {
 	.type = IIO_ANGL,
 	.indexed = 1,
 	.channel = 0,
-	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
 };
 
 static int ad2s90_probe(struct spi_device *spi)
-- 
2.18.0


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

* [PATCH 6/6] staging:iio:ad2s90: Check channel type at read_raw
  2018-10-26  0:45 [PATCH 0/6] staging:iio:ad2s90: Add scale info and improve error handling Matheus Tavares
                   ` (4 preceding siblings ...)
  2018-10-26  0:45 ` [PATCH 5/6] staging:iio:ad2s90: Add IIO_CHAN_INFO_SCALE to channel spec and read_raw Matheus Tavares
@ 2018-10-26  0:45 ` Matheus Tavares
  5 siblings, 0 replies; 9+ messages in thread
From: Matheus Tavares @ 2018-10-26  0:45 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Hartmut Knaack, Peter Meerwald-Stadler, Greg Kroah-Hartman
  Cc: linux-iio, devel, linux-kernel, kernel-usp

This patch adds a channel type check at the beginning of the
ad2s90_read_raw function. Since ad2s90 has only one channel, it just
checks if the given channel is the expected one and if not, return
-EINVAL.

Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
---
 drivers/staging/iio/resolver/ad2s90.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/staging/iio/resolver/ad2s90.c b/drivers/staging/iio/resolver/ad2s90.c
index 52b656875ed1..24002042a5c5 100644
--- a/drivers/staging/iio/resolver/ad2s90.c
+++ b/drivers/staging/iio/resolver/ad2s90.c
@@ -34,6 +34,9 @@ static int ad2s90_read_raw(struct iio_dev *indio_dev,
 	int ret;
 	struct ad2s90_state *st = iio_priv(indio_dev);
 
+	if (chan->type != IIO_ANGL)
+		return -EINVAL;
+
 	switch (m) {
 	case IIO_CHAN_INFO_SCALE:
 		/* 2 * Pi / (2^12 - 1) ~= 0.001534355 */
-- 
2.18.0


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

* Re: [PATCH 5/6] staging:iio:ad2s90: Add IIO_CHAN_INFO_SCALE to channel spec and read_raw
  2018-10-26  0:45 ` [PATCH 5/6] staging:iio:ad2s90: Add IIO_CHAN_INFO_SCALE to channel spec and read_raw Matheus Tavares
@ 2018-10-26 10:04   ` Dan Carpenter
  2018-10-26 18:56     ` Matheus Tavares Bernardino
  0 siblings, 1 reply; 9+ messages in thread
From: Dan Carpenter @ 2018-10-26 10:04 UTC (permalink / raw)
  To: Matheus Tavares
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Hartmut Knaack, Peter Meerwald-Stadler, Greg Kroah-Hartman,
	linux-iio, devel, Victor Colombo, linux-kernel, kernel-usp

On Thu, Oct 25, 2018 at 09:45:11PM -0300, Matheus Tavares wrote:
> From: Victor Colombo <victorcolombo@gmail.com>
> 
> This patch adds the IIO_CHAN_INFO_SCALE mask to ad2s90_chan and
> implements the relative read behavior at ad2s90_read_raw.
> 
> Signed-off-by: Victor Colombo <victorcolombo@gmail.com>
> ---

You should be adding your S-o-B here as well because the patch is
passing through your hands.

regards,
dan carpenter


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

* Re: [PATCH 5/6] staging:iio:ad2s90: Add IIO_CHAN_INFO_SCALE to channel spec and read_raw
  2018-10-26 10:04   ` Dan Carpenter
@ 2018-10-26 18:56     ` Matheus Tavares Bernardino
  0 siblings, 0 replies; 9+ messages in thread
From: Matheus Tavares Bernardino @ 2018-10-26 18:56 UTC (permalink / raw)
  To: dan.carpenter
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Hartmut Knaack, Peter Meerwald-Stadler, Greg Kroah-Hartman,
	linux-iio, devel, Victor Colombo, linux-kernel, kernel-usp

On Fri, Oct 26, 2018 at 7:04 AM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> On Thu, Oct 25, 2018 at 09:45:11PM -0300, Matheus Tavares wrote:
> > From: Victor Colombo <victorcolombo@gmail.com>
> >
> > This patch adds the IIO_CHAN_INFO_SCALE mask to ad2s90_chan and
> > implements the relative read behavior at ad2s90_read_raw.
> >
> > Signed-off-by: Victor Colombo <victorcolombo@gmail.com>
> > ---
>
> You should be adding your S-o-B here as well because the patch is
> passing through your hands.

Thanks for the review! I'll be sending a v2 with my S-o-B there.

> regards,
> dan carpenter
>
> --
> You received this message because you are subscribed to the Google Groups "Kernel USP" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kernel-usp+unsubscribe@googlegroups.com.
> To post to this group, send email to kernel-usp@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kernel-usp/20181026100422.lvz2avowd6ddix54%40mwanda.
> For more options, visit https://groups.google.com/d/optout.

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

end of thread, other threads:[~2018-10-26 18:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-26  0:45 [PATCH 0/6] staging:iio:ad2s90: Add scale info and improve error handling Matheus Tavares
2018-10-26  0:45 ` [PATCH 1/6] staging:iio:ad2s90: Make read_raw return spi_read's error code Matheus Tavares
2018-10-26  0:45 ` [PATCH 2/6] staging:iio:ad2s90: Make probe handle spi_setup failure Matheus Tavares
2018-10-26  0:45 ` [PATCH 3/6] staging:iio:ad2s90: Remove always overwritten assignment Matheus Tavares
2018-10-26  0:45 ` [PATCH 4/6] staging:iio:ad2s90: Move device registration to the end of probe Matheus Tavares
2018-10-26  0:45 ` [PATCH 5/6] staging:iio:ad2s90: Add IIO_CHAN_INFO_SCALE to channel spec and read_raw Matheus Tavares
2018-10-26 10:04   ` Dan Carpenter
2018-10-26 18:56     ` Matheus Tavares Bernardino
2018-10-26  0:45 ` [PATCH 6/6] staging:iio:ad2s90: Check channel type at read_raw Matheus Tavares

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).