mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk>
To: Felipe Tonello <eu@felipetonello.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jslaby@suse.cz>,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Subject: Re: [PATCH] char: Added support for u-blox 6 i2c gps driver
Date: Thu, 15 Jan 2015 11:29:53 +0000	[thread overview]
Message-ID: <20150115112953.27cc5934@lxorguk.ukuu.org.uk> (raw)
In-Reply-To: <CAGrhNMysmq==Y0naNki0z5usmMwUErj-FOTy=8KH0V=R7=VFwA@mail.gmail.com>

Which kernel did you see the write_room oops ? and I'll double check its
all fixed.

> >> +     ublox_gps_i2c_client = client;
> >> +     ublox_gps_filp = NULL;
> >> +     ublox_gps_tty_port = NULL;
> >> +     ublox_gps_is_open = false;
> >
> > There are some other i2c based tty drivers in the kernel - notably those
> > in drivers/tty/serial that use the uart layer to deal with most of the
> > awkward locking cases.
> >
> > You can do it by hand but it's fairly hairy (see
> > drivers/mmc/card/sdio_uart.c, so it might be simplest to tweak the driver
> > to use the uart layer. You don't really gain much from it for your driver
> > except easier locking - but the locking is rather handy.
> >
> > Alan
> 
> Ok.
> 
> The thing is that: I wrote this driver to work with only one gps
> module, because that's my configuration here. I cannot really test
> multiple i2c gps at the same time. If you guys really want a driver
> that works for multiple gps drivers, I cannot test it.

It isn't just about multiple GPS devices, it's about locking. What stops
things being unloaded or reloaded and freeing memory you are still using.
Things happen in parallel. If you have an i2c hot unplug happen as
you are running your worker thread for example this would occur

	Device still plugged in
               if (!ublox_gps_i2c_client)
	       {False so we continue}
	Device unplugged
               Use ublock_gps_i2c_client
               *Kaboom*

There are two ways to deal with that

1. Don't free the resources until the device is not being used (so while
the hardware may have walked the memory and pointers are still valid)

2. take a lock before checking, drop it after you finish using the
object. Take the same lock when destroying it.

The kernel mostly does #1, in part because the second case tends to be
hard to get right and avoid deadlocks.

I'm much less worried about the single device parts of it. The static
values you have are fairly easy to deal with I think

ublox_gps_filp isn't needed (its only used for bogus tests)
ublox_gps_is_open isn't needed (it's only used for the open test)

ublox_gps_i2c_client belongs as a pointer in your tty_data
ublox_gps_tty_port belongs as the client pointer in your i2c


      parent reply	other threads:[~2015-01-15 11:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-14  1:16 Felipe F. Tonello
2015-01-14  1:33 ` Greg Kroah-Hartman
2015-01-14  2:07   ` Felipe Tonello
2015-01-14  4:10     ` Greg Kroah-Hartman
2015-01-14 15:48 ` One Thousand Gnomes
2015-01-14 18:39   ` Felipe Tonello
2015-01-14 20:43     ` Greg Kroah-Hartman
2015-01-15 11:29     ` One Thousand Gnomes [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=20150115112953.27cc5934@lxorguk.ukuu.org.uk \
    --to=gnomes@lxorguk.ukuu.org.uk \
    --cc=eu@felipetonello.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@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

all inboxes | Powered by JetHome®