All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: Joe Perches <joe@perches.com>,
	Jonathan Cameron <jic23@kernel.org>,
	linux-iio <linux-iio@vger.kernel.org>
Subject: Re: [PATCH 4/4] iio: dac: Convert powerdown read callbacks to sysfs_emit()
Date: Mon, 29 Mar 2021 14:21:48 +0300	[thread overview]
Message-ID: <CAHp75VdV0YjL2uBWS5SQsH=PfLkWRu5_bTWbfLFUO+hEc0B2OA@mail.gmail.com> (raw)
In-Reply-To: <3e26d657-4f03-5284-8cfe-73131a65e33f@metafoo.de>

On Sat, Mar 20, 2021 at 2:54 PM Lars-Peter Clausen <lars@metafoo.de> wrote:
> On 3/20/21 12:01 PM, Joe Perches wrote:
> > On Sat, 2021-03-20 at 08:14 +0100, Lars-Peter Clausen wrote:
> >> Update DAC drivers powerdown attribute show callback to use the new
> >> sysfs_emit() function.
> >>
> >> sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
> >> knows about the sysfs buffer specifics and has some built-in sanity checks.
> > Thanks.
> >
> > unrelated trivia:
> >
> >> diff --git a/drivers/iio/dac/ad5360.c b/drivers/iio/dac/ad5360.c
> > []
> >> @@ -255,7 +255,7 @@ static ssize_t ad5360_read_dac_powerdown(struct device *dev,
> >>      struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> >>      struct ad5360_state *st = iio_priv(indio_dev);
> >>
> >> -    return sprintf(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN));
> >> +    return sysfs_emit(buf, "%d\n", (bool)(st->ctrl & AD5360_SF_CTRL_PWR_DOWN));
> > rather than cast to bool, perhaps standardize to use !!(val & test)
> I very much prefer the cast to bool since it semantically stronger.

It's a mistake here. You have no special type for bool and you do
transition int -> bool -> int.
Why? !! is a proper way to deal with this.

> You
> don't have to know that the !! idiom is used to cast an int to bool.

As Joe said.


-- 
With Best Regards,
Andy Shevchenko

  parent reply	other threads:[~2021-03-29 11:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-20  7:14 [PATCH 0/4] iio: Start conversion to sysfs_emit() Lars-Peter Clausen
2021-03-20  7:14 ` [PATCH 1/4] iio: core: Use sysfs_emit() (trivial bits) Lars-Peter Clausen
2021-03-20  7:14 ` [PATCH 2/4] iio: iio_enum_available_read(): Convert to sysfs_emit_at() Lars-Peter Clausen
2021-03-20  7:14 ` [PATCH 3/4] iio: __iio_format_value(): " Lars-Peter Clausen
2021-03-20  7:14 ` [PATCH 4/4] iio: dac: Convert powerdown read callbacks to sysfs_emit() Lars-Peter Clausen
2021-03-20 11:01   ` Joe Perches
2021-03-20 12:52     ` Lars-Peter Clausen
2021-03-20 15:13       ` Joe Perches
2021-03-29 10:13         ` Jonathan Cameron
2021-03-29 11:21       ` Andy Shevchenko [this message]
2021-03-29 11:22         ` Andy Shevchenko
2021-03-29 11:27   ` Andy Shevchenko
2021-03-20 18:34 ` [PATCH 0/4] iio: Start conversion " 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='CAHp75VdV0YjL2uBWS5SQsH=PfLkWRu5_bTWbfLFUO+hEc0B2OA@mail.gmail.com' \
    --to=andy.shevchenko@gmail.com \
    --cc=jic23@kernel.org \
    --cc=joe@perches.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@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 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.