mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: "Fernando Apesteguía" <fernando.apesteguia@gmail.com>
Cc: devel@driverdev.osuosl.org, Lidza Louina <lidza.louina@gmail.com>,
	driverdev-devel@linuxdriverproject.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: dgnc: replace DGNC_VERIFY_BOARD macro
Date: Tue, 18 Oct 2016 08:40:18 +0200	[thread overview]
Message-ID: <20161018064018.GB7796@kroah.com> (raw)
In-Reply-To: <CAGwOe2YfAKsifsjXr9fydMfVV+Obv-1mBebXwXAWrNHSNJt+mg@mail.gmail.com>

On Mon, Oct 17, 2016 at 11:46:36PM +0200, Fernando Apesteguía wrote:
> On Mon, Oct 17, 2016 at 10:29 AM, Greg KH <gregkh@linuxfoundation.org> wrote:
> > On Fri, Oct 14, 2016 at 07:22:57PM +0200, Fernando Apesteguia wrote:
> >> The patch replaces the macro with a function (dgnc_get_board) and
> >> substitutes the macro statement with a call to that function and a
> >> comparison on the returned value.
> >>
> >> This removes a checkpatch warning.
> >>
> >> Signed-off-by: Fernando Apesteguia <fernando.apesteguia@gmail.com>
> >> ---
> >>  drivers/staging/dgnc/dgnc_sysfs.c | 74 +++++++++++++++++++++++++++------------
> >>  1 file changed, 51 insertions(+), 23 deletions(-)
> >>
> >> diff --git a/drivers/staging/dgnc/dgnc_sysfs.c b/drivers/staging/dgnc/dgnc_sysfs.c
> >> index 290bf6e..3ea23a9 100644
> >> --- a/drivers/staging/dgnc/dgnc_sysfs.c
> >> +++ b/drivers/staging/dgnc/dgnc_sysfs.c
> >> @@ -90,17 +90,21 @@ void dgnc_remove_driver_sysfiles(struct pci_driver *dgnc_driver)
> >>       driver_remove_file(driverfs, &driver_attr_pollrate);
> >>  }
> >>
> >> -#define DGNC_VERIFY_BOARD(p, bd)                             \
> >> -     do {                                                    \
> >> -             if (!p)                                         \
> >> -                     return 0;                               \
> >> -                                                             \
> >> -             bd = dev_get_drvdata(p);                        \
> >> -             if (!bd || bd->magic != DGNC_BOARD_MAGIC)       \
> >> -                     return 0;                               \
> >> -             if (bd->state != BOARD_READY)                   \
> >> -                     return 0;                               \
> >> -     } while (0)
> >> +static struct dgnc_board *dgnc_get_board(struct device *p)
> >> +{
> >> +     struct dgnc_board *bd;
> >> +
> >> +     if (!p)
> >> +             return NULL;
> >> +
> >> +     bd = dev_get_drvdata(p);
> >> +     if (!bd || bd->magic != DGNC_BOARD_MAGIC)
> >> +             return NULL;
> >> +     if (bd->state != BOARD_READY)
> >> +             return NULL;
> >> +
> >> +     return bd;
> >> +}
> >
> > No, this macro should be removed entirely as what it does is pointless
> > in some parts, wrong in others, and not needed at all in the rest :(
> >
> > I've asked others to fix this up properly in the past, but it doesn't
> > seem like anyone wants to do the work...
> >
> 
> I tried to find the discussion the relevant mails in lkml.org but
> couldn't find them. Could  you point me to them so I can have a look?

Last time I mentioned this, it was on the outreachy-kernel mailing list.

Just walk through the code for yourself and see which, if any, of these
things could ever actually cause the function to "fail".  I think you
will find that none of them can ever happen...

The first test is a huge proof that the original author didn't
understand how sysfs or "container_of()" works, given that it is
impossible to ever have happen.

thanks,

greg k-h

      reply	other threads:[~2016-10-18  6:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-14 17:22 Fernando Apesteguia
2016-10-17  8:29 ` Greg KH
2016-10-17 21:46   ` Fernando Apesteguía
2016-10-18  6:40     ` Greg KH [this message]

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=20161018064018.GB7796@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=devel@driverdev.osuosl.org \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=fernando.apesteguia@gmail.com \
    --cc=lidza.louina@gmail.com \
    --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

Powered by JetHome