linux-watchdog.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Thumshirn <johannes.thumshirn@men.de>
To: Guenter Roeck <linux@roeck-us.net>
Cc: Johannes Thumshirn <johannes.thumshirn@men.de>, <wim@iguana.be>,
	<linux-watchdog@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: Some problems with sysfs patch (was Re: [PATCH v6] watchdog: New watchdog driver for MEN A21 watchdogs)
Date: Fri, 7 Jun 2013 11:49:06 +0200	[thread overview]
Message-ID: <20130607094906.GA18730@jtlinux> (raw)
In-Reply-To: <20130607091419.GA2180@roeck-us.net>

On Fri, Jun 07, 2013 at 02:14:19AM -0700, Guenter Roeck wrote:
> On Fri, Jun 07, 2013 at 09:45:19AM +0200, Johannes Thumshirn wrote:
> > On Thu, Jun 06, 2013 at 10:08:28AM -0700, Guenter Roeck wrote:
> > > On Thu, Jun 06, 2013 at 03:00:55PM +0200, Johannes Thumshirn wrote:
> > > > On Thu, Jun 06, 2013 at 04:31:10AM -0700, Guenter Roeck wrote:
> > > > > On Thu, Jun 06, 2013 at 12:51:03PM +0200, Johannes Thumshirn wrote:
> > > > > > On Mon, Jun 03, 2013 at 11:50:26AM +0200, Johannes Thumshirn wrote:
> > > > > > > On Fri, May 31, 2013 at 09:15:23PM -0700, Guenter Roeck wrote:
> > > > > > > > On Fri, May 31, 2013 at 02:55:19PM +0200, Johannes Thumshirn wrote:
> > > > > > > > > Hi Guenther,
> > > > > > > > > On Fri, May 31, 2013 at 04:40:37AM -0700, Guenter Roeck wrote:
> > > > > > > > > > > +#define GPIO_WD_ENAB	169
> > > > > > > > > > > +#define GPIO_WD_FAST	170
> > > > > > > > > > > +#define GPIO_WD_TRIG	171
> > > > > > > > > > > +
> > > > > > > > > > > +#define GPIO_RST_CAUSE_BASE 166
> > > > > > > > > > > +
> > > > > > > > > >
> > > > > > > > > > I think I asked that before ... as you are supporting devicetree, gpio pins
> > > > > > > > > > should really be provided through devicetree properties and not be hardcoded.
> > > > > > > > > >
> > > > > > > > > Yes you did and I didn't come up with a solution to this problem yet. I understand
> > > > > > > > > and agree to your concerns but I'm lacking example code/documentation for it, maybe
> > > > > > > > > you can point me to an example on that and then I'll update my code accordingly.
> > > > > > > > >
> > > > > > > >
> > > > > > > > Have a look at Documentation/devicetree/bindings/gpio/gpio-fan.txt and
> > > > > > > > drivers/hwmon/gpio-fan.c.
> > > > > > >
> > > > > > > Thanks a lot, this really helped me out. Updated patch is comming today
> > > > > > > including the bindings document Arnd Bergmann requested. I only need to rebase
> > > > > > > the sysfs patch on top of that changes.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Johannes
> > > > > >
> > > > > > Regarding the sysfs patch, I have a funny effect in my (rebased) sysfs code.
> > > > > >
> > > > > > Given the following code:
> > > > > >
> > > > > > +static ssize_t rebootcause_show(struct device *dev,
> > > > > > +                               struct device_attribute *attr,
> > > > > > +                               char *buf)
> > > > > > +{
> > > > > > +       struct a21_wdt_drv *drv = dev_get_drvdata(dev);
> > > > > > +       unsigned int reset = 0;
> > > > > > +
> > > > > > +       if (!drv)
> > > > > > +               return -EIO;
> > > > > > +
> > > > > > +       reset = a21_wdt_get_bootstatus(drv);
> > > > > > +
> > > > > > +       return sprintf(buf, "%s\n", reset_causes[reset]);
> > > > > > +}
> > > > > > +static DEVICE_ATTR(rebootcause, S_IRUGO, rebootcause_show, NULL);
> > > > > >
> > > > > > I actually need the check for if (!drv) to prevent an OOPS, as
> > > > > > dev_get_drvdata(dev) returns NULL., though it is set at the end of my probe
> > > > > > function via:
> > > > > >
> > > > > > [...]
> > > > > > +       ret = watchdog_register_device(&a21_wdt);
> > > > > > +       if (ret) {
> > > > > > +               dev_err(&pdev->dev, "Cannot register watchdog device\n");
> > > > > > +               goto err_register_wd;
> > > > > > +       }
> > > > > > +
> > > > > > +       dev_set_drvdata(&pdev->dev, drv);
> > > > > > +
> > > > > > +       return 0;
> > > > > > [...]
> > > > > >
> > > > > > The watchdog driver itself is working without any troubles.
> > > > > >
> > > > > > Some advice here would be worth its weight in gold.
> > > > > >
> > > > > It has to be set before the attribute is created. Are you doing that ? Also, is
> > > > > 'dev' the same device pointer (ie is the 'dev' in your function the same as
> > > > > &pdev->dev) ?
> > > > >
> > > > > Guenter
> > > >
> > > > Hi Guenter,
> > > >
> > > > Thanks for the quick reply. Indeed 'dev' in my function is a struct
> > > > watchdog_device's dev (for device_create_file) and not &pdev->dev. Which in turn
> > > > are not the same.
> > > >
> > > > A call to dev_set_drvdata(a21_wdt.dev, drv); solved the NULL pointer access. So
> > > > last question, is it save to set the drvdata of a dev inside the struct
> > > > watchdog_device or do I break something vital that way?
> > > >
> > > Good question. At issue is if your driver 'owns' struct watchdog_device,
> > > or if the watchdog core owns it.
> > >
> > > However, since you know that a21_wdt.dev is the device, you can use
> > > container_of() to get a reference to a21_wdt, and watchdog_get_drvdata
> > > to get access to drv from a21_wdt. So you should not really need it.
> > >
> > > Thanks,
> > > Guenter
> >
> > OK, but doesn't the container_of() macro only work if the parent struct embeds
> > the child struct and not a pointer to it? But struct watchdog_device only has a
> > pointer to a struct device (checked my 3.10-rc4 as well as watchdog-next/master,
> > just in case I missed something).
> >
> Yes, you are right, sorry for the noise.
>
> Guenter

No problem. Actually I hoped you tell me I was wrong and point me to the right
practice for this.

Anyway I'll send the patch as it is and hope it's clean for inclusion.

Thanks for your help.

Johannes


  reply	other threads:[~2013-06-07  9:46 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-31  8:58 [PATCH v5 1/2] watchdog: New watchdog driver for MEN A21 watchdogs Johannes Thumshirn
2013-05-31  9:01 ` [PATCH v2 2/2] This patch adds a sysfs interface for the watchdog device found on MEN A21 Boards Johannes Thumshirn
2013-05-31  9:04 ` [PATCH v5 1/2] watchdog: New watchdog driver for MEN A21 watchdogs Johannes Thumshirn
2013-05-31 10:36 ` Guenter Roeck
2013-05-31 10:53   ` Johannes Thumshirn
2013-05-31 11:08   ` [PATCH v6] " Johannes Thumshirn
2013-05-31 11:40     ` Guenter Roeck
2013-05-31 12:55       ` Johannes Thumshirn
2013-06-01  4:15         ` Guenter Roeck
2013-06-03  9:50           ` Johannes Thumshirn
2013-06-06 10:51             ` Some problems with sysfs patch (was Re: [PATCH v6] watchdog: New watchdog driver for MEN A21 watchdogs) Johannes Thumshirn
2013-06-06 11:31               ` Guenter Roeck
2013-06-06 13:00                 ` Johannes Thumshirn
2013-06-06 17:08                   ` Guenter Roeck
2013-06-07  7:45                     ` Johannes Thumshirn
2013-06-07  9:14                       ` Guenter Roeck
2013-06-07  9:49                         ` Johannes Thumshirn [this message]
2013-05-31 13:32       ` [PATCH v7] watchdog: New watchdog driver for MEN A21 watchdogs Johannes Thumshirn
2013-06-01 15:28         ` Guenter Roeck
2013-06-03 14:34       ` [PATCH v8] " Johannes Thumshirn
2013-06-07  9:55         ` [PATCH v8 2/2] watchdog: Sysfs interface for MEN A21 watchdog Johannes Thumshirn
2013-06-14  3:55         ` [PATCH v8] watchdog: New watchdog driver for MEN A21 watchdogs Guenter Roeck
2013-06-14  7:39           ` Johannes Thumshirn
2013-06-14 10:58         ` [PATCH v9] " Johannes Thumshirn
2013-06-14 11:19           ` [PATCH v9 2/2] watchdog: Sysfs interface for MEN A21 watchdog Johannes Thumshirn
2013-06-16 22:07           ` [PATCH v9] watchdog: New watchdog driver for MEN A21 watchdogs Guenter Roeck
2013-06-17  6:40             ` Johannes Thumshirn
2013-06-17 10:22             ` [PATCH v10 1/2] " Johannes Thumshirn
2013-06-17 10:24               ` [PATCH v10 2/2] watchdog: Sysfs interface for MEN A21 watchdog Johannes Thumshirn
2013-06-17 14:00               ` [PATCH v10 1/2] watchdog: New watchdog driver for MEN A21 watchdogs Guenter Roeck
2013-06-18 15:19                 ` [PATCH RESEND " Johannes Thumshirn
2013-06-18 15:21                   ` [PATCH RESEND v10 2/2] watchdog: Sysfs interface for MEN A21 watchdog Johannes Thumshirn
2013-07-01  7:32                     ` Johannes Thumshirn
2013-07-05 21:03                     ` Wim Van Sebroeck
2013-07-08  7:06                       ` Johannes Thumshirn
2013-07-05 21:01                   ` [PATCH RESEND v10 1/2] watchdog: New watchdog driver for MEN A21 watchdogs Wim Van Sebroeck
2013-07-08  6:59                     ` Johannes Thumshirn
2013-06-01  8:56 ` [PATCH v5 " Arnd Bergmann

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=20130607094906.GA18730@jtlinux \
    --to=johannes.thumshirn@men.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=wim@iguana.be \
    /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;
as well as URLs for NNTP newsgroup(s).