kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: greg@kroah.com (Greg KH)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Logging communication with devices
Date: Sun, 4 Oct 2015 12:26:56 +0100	[thread overview]
Message-ID: <20151004112656.GA8490@kroah.com> (raw)
In-Reply-To: <CA+MoWDqg7yNEskJaiTasJL2bKBGX-Onmqxe4jOuDVOUkcGB=dg@mail.gmail.com>

On Sun, Oct 04, 2015 at 01:18:29PM +0200, Peter Senna Tschudin wrote:
> Does Linux provide an elegant and/or standard way of logging
> communication with devices that manage buffers and that can help me
> improve code like:
> 
> $ cat drivers/usb/host/fotg210-hcd.c
> ...
>                 temp = snprintf(next, size,
>                                 "\n\t%p%c%s len=%d %08x urb %p",
>                                 td, mark, ({ char *tmp;
>                                  switch ((scratch>>8)&0x03) {
>                                  case 0:
>                                         tmp = "out";
>                                         break;
>                                  case 1:
>                                         tmp = "in";
>                                         break;
>                                  case 2:
>                                         tmp = "setup";
>                                         break;
>                                  default:
>                                         tmp = "?";
>                                         break;
>                                  } tmp; }),
>                                 (scratch >> 16) & 0x7fff,
>                                 scratch,
>                                 td->urb);
> 

What is this mess?

/me digs in the driver...

Hm, it's actually not that bad.  Well, besides the horrid logic here,
this is all debugfs file information to help people see what is going on
in the internals of the driver as its running.  It seems to be using the
correct debugfs apis to handle the buffer management properly, which is
a nice surprise.

So while you could work on cleaning up that crazy snprintf call to be
"nicer", I'd just leave it alone.  It obviously must work as the
developer used it when creating the code, so let's just trust that it is
correct and walk away slowly...

thanks,

greg k-h

      reply	other threads:[~2015-10-04 11:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-04 11:18 Logging communication with devices Peter Senna Tschudin
2015-10-04 11:26 ` 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=20151004112656.GA8490@kroah.com \
    --to=greg@kroah.com \
    --cc=kernelnewbies@lists.kernelnewbies.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;
as well as URLs for NNTP newsgroup(s).