mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tomas Melin <tomas.melin@vaisala.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	devicetree <devicetree@vger.kernel.org>,
	linux-iio <linux-iio@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 2/2] iio: accel: Add driver for Murata SCA3300 accelerometer
Date: Mon, 19 Apr 2021 14:36:15 +0300	[thread overview]
Message-ID: <9d6e9205-6fcd-1112-46da-2062e12311e1@vaisala.com> (raw)
In-Reply-To: <CAHp75VcWu96EAjzYYwt_gqscvJp3s9Y+ZnaK2NQa_=L+S+r5zQ@mail.gmail.com>

Hi,

On 4/19/21 2:14 PM, Andy Shevchenko wrote:
> On Mon, Apr 19, 2021 at 1:29 PM Tomas Melin <tomas.melin@vaisala.com> wrote:
>> On 4/17/21 3:39 PM, Andy Shevchenko wrote:
>>> On Fri, Apr 16, 2021 at 5:21 PM Tomas Melin <tomas.melin@vaisala.com> wrote:
>>>> Add initial support for Murata SCA3300 3-axis industrial
>>>> accelerometer with digital SPI interface. This device also
>>>> provides a temperature measurement.
> ...
>
>>>> +       ret = spi_sync_transfer(sca_data->spi, xfers, ARRAY_SIZE(xfers));
>>>> +       if (ret < 0) {
>>>> +               dev_err(&sca_data->spi->dev,
>>>> +                       "transfer error, error: %d\n", ret);
>>>> +               return -EIO;
>>> Why shadowing error code?
>> Returning EIO here to have full control over the return value from this
>> function. As return value of this is used for testing
> Care to show what kind of testing requires this?
> Also why can't it be refactored to accept all error codes?

I was referring to this:

+static int sca3300_read_reg(struct sca3300_data *sca_data, u8 reg, int *val)
+{
+	int ret;
+
+	mutex_lock(&sca_data->lock);
+	sca_data->txbuf[0] = 0x0 | (reg << 2);
+	ret = sca3300_transfer(sca_data, val);
+	mutex_unlock(&sca_data->lock);
+	if (ret == -EINVAL)
+		ret  = sca3300_error_handler(sca_data);
+
+	return ret;
+}
+
+static int sca3300_write_reg(struct sca3300_data *sca_data, u8 reg, int val)
+{
+	int reg_val = 0;
+	int ret;
+
+	mutex_lock(&sca_data->lock);
+	sca_data->txbuf[0] = BIT(7) | (reg << 2);
+	put_unaligned_be16(val, &sca_data->txbuf[1]);
+	ret = sca3300_transfer(sca_data, &reg_val);
+	mutex_unlock(&sca_data->lock);
+	if (ret == -EINVAL)
+		ret  = sca3300_error_handler(sca_data);
+
+	return ret;
+}

So this goes into error handling only when transfer indicates EINVAL 
(which happens when

transfer otherwise is good, but device return status has error flags set 
i message).

Thanks,

Tomas


>
>> for possible status error (EINVAL), feels more confident to have it like
>> this to avoid any confusion. And atleast spi_sync_transfer() return value
>>
>> would be visible in error message.
>>>> +       }
>
>

  reply	other threads:[~2021-04-19 11:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-16 13:45 iio: accel: sca3300: Accelerometer support and binding docs Tomas Melin
2021-04-16 13:45 ` [PATCH v2 1/2] dt-bindings: iio: accel: Add SCA3300 documentation Tomas Melin
2021-04-16 13:45 ` [PATCH v2 2/2] iio: accel: Add driver for Murata SCA3300 accelerometer Tomas Melin
2021-04-17 12:39   ` Andy Shevchenko
2021-04-18 11:26     ` Jonathan Cameron
2021-04-19 10:29     ` Tomas Melin
2021-04-19 11:14       ` Andy Shevchenko
2021-04-19 11:36         ` Tomas Melin [this message]
2021-04-19 12:29           ` Andy Shevchenko
2021-04-19 12:48             ` Tomas Melin
2021-04-18 12:08   ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9d6e9205-6fcd-1112-46da-2062e12311e1@vaisala.com \
    --to=tomas.melin@vaisala.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®