public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Kay Sievers <kay@vrfy.org>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Alan Stern <stern@rowland.harvard.edu>,
	linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
	Henrik Rydberg <rydberg@euromail.se>
Subject: Re: proper struct device selection for dev_printk()
Date: Thu, 3 May 2012 17:07:40 -0700	[thread overview]
Message-ID: <20120504000740.GC32225@kroah.com> (raw)
In-Reply-To: <CAPXgP11ktmMcLvwYy9PvyZ_J9bmmAzdmqzKCVE6Q0dbKHyG9eg@mail.gmail.com>

On Thu, May 03, 2012 at 09:12:43PM +0200, Kay Sievers wrote:
> On Thu, May 3, 2012 at 8:47 PM, Dmitry Torokhov
> <dmitry.torokhov@gmail.com> wrote:
> > On Thu, May 03, 2012 at 07:50:52PM +0200, Kay Sievers wrote:
> 
> >> I guess it all depends who is the consumer of the messages, and I
> >> would say if userspace is the intended consumer, always use the device
> >> that provides the access/interface to userspace. It's easy to walk up
> >> the tree and find out about the other things.
> >
> > This would be:
> >
> > 1. Impossible in most cases
> > 2. If it was possible it woudl have to be layer violation.
> 
> Yeah, if it would be easy, Greg would not have written the mail. :)
> 
> > Taking psmouse as an example you have no idea which interface to use to
> > report errors - mouse2, event6 or js1 - these are what visible from
> > userspace and all of them could report to the same input device.
> 
> True, if the error does not propagate up to the class device, it does
> not sound right to do that. But it's still the case that userspace or
> any automated message consumer cannot make much sense out of the
> message then. It's still targeted at a human.

Yes, that's the point here, what is a human supposed to do with this?

> > We
> > however know exactly what serio port we had trouble with.
> 
> Sure, if the error occurs in that context, it should be logged with
> exactly that context. If it propagates up to the higher devices they
> should log themselves.
> 
> The point I tried to make was, that we should not in general walk up
> to the next bus device for logging, and that the parent devices are
> not more useful in general. I wanted to express that a rule like: "In
> general, drivers should emit messages for the devices they bind to."
> is not the right thing to do, if we *can* establish a context to the
> device that is used in userspace.
> 
> But sure, if the error can not be propagated to the child devices, we
> should not fake anything here either, but the stuff should stay where
> it happened.

Ok, so it is probably best to use the struct device that the piece of
code has control over.  Which sometimes is not the lowest one, but
sometimes it is.  That's a good rule to go by, thanks everyone.

In my original example, out of:
        dev_err(&port->dev, "dev_err port->dev output\n");
        dev_err(&serial->dev->dev, "dev_err serial->dev->dev output\n");
        dev_err(&serial->interface->dev, "dev_err serial->interface->dev output\n");
        dev_err(port->port.tty->dev, "dev_err port->port.tty->dev output\n");
        [   68.519639] pl2303 ttyUSB0: dev_err port->dev output
        [   68.519645] usb 2-1.2: dev_err serial->dev->dev output
        [   68.519649] pl2303 2-1.2:1.0: dev_err serial->interface->dev output
        [   68.519653] tty ttyUSB0: dev_err port->port.tty->dev output

I will choose the first one, "&port->dev" as that is what the driver
controls at this point in time.  Sometimes, it's only the USB interface
that it knows about (like in the probe() and release() USB callbacks),
but for the most part, it will be consistant.

So, Dmitry, this agrees with your original complaint as well, the input
device isn't the right thing to do, but the USB interface is.  I'll go
rework those patches again (third times a charm, right?) to do it that
way.

thanks,

greg k-h

      reply	other threads:[~2012-05-04  0:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-03 16:09 proper struct device selection for dev_printk() Greg KH
2012-05-03 17:10 ` Dmitry Torokhov
2012-05-03 17:21   ` Alan Stern
2012-05-03 17:50     ` Kay Sievers
2012-05-03 18:47       ` Dmitry Torokhov
2012-05-03 19:12         ` Kay Sievers
2012-05-04  0:07           ` 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=20120504000740.GC32225@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=kay@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=rydberg@euromail.se \
    --cc=stern@rowland.harvard.edu \
    /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