From: Greg KH on
On Fri, Aug 06, 2010 at 08:29:28PM +0400, Dmitry Eremin-Solenikov wrote:
> Some device drivers (mostly tty line disciplines) would like to have way
> to get a struct device instancve corresponding to passed tty_struct. Add
> respective API call.
>
> Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov(a)gmail.com>
> ---
> drivers/char/tty_io.c | 20 ++++++++++++++++++++
> include/linux/tty.h | 1 +
> 2 files changed, 21 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
> index d71f0fc..43fdeef 100644
> --- a/drivers/char/tty_io.c
> +++ b/drivers/char/tty_io.c
> @@ -3017,6 +3017,26 @@ dev_t tty_devnum(struct tty_struct *tty)
> }
> EXPORT_SYMBOL(tty_devnum);
>
> +static int dev_match_devt(struct device *dev, void *data)
> +{
> + dev_t *devt = data;
> + return dev->devt == *devt;
> +}
> +
> +/**
> + * tty_get_device - get a device corresponding to tty
> + * @tty: the struct that describes the tty device
> + *
> + * Returns a pointer to the struct device for this tty device
> + * (or NULL in case of error).

You should add some wording here that says that the device now has an
increased reference count and that you better drop it when you are done
with it, otherwise it will stay around for a while.

Other than that, I like the idea.

Care to redo it?

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Alan Cox on
On Sat, 7 Aug 2010 13:55:02 +0400
Dmitry Eremin-Solenikov <dbaryshkov(a)gmail.com> wrote:

> Some device drivers (mostly tty line disciplines) would like to have way
> to get a struct device instancve corresponding to passed tty_struct. Add
> respective API call.

Most of the kernel simply keeps a parent device pointer in the struct. If
we have a lookup method then we'll simply end up with a struct device in
each tty ldisc struct instead, and it will be harder to clean up later.

I think I'd much rather see this set when the tty is created and always
available. That would also let the whole tty layer use dev_err() and
friends usefully ?

Alan
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Dmitry Eremin-Solenikov on
On Sat, Aug 07, 2010 at 12:33:33PM +0100, Alan Cox wrote:
> On Sat, 7 Aug 2010 13:55:02 +0400
> Dmitry Eremin-Solenikov <dbaryshkov(a)gmail.com> wrote:
>
> > Some device drivers (mostly tty line disciplines) would like to have way
> > to get a struct device instancve corresponding to passed tty_struct. Add
> > respective API call.
>
> Most of the kernel simply keeps a parent device pointer in the struct. If
> we have a lookup method then we'll simply end up with a struct device in
> each tty ldisc struct instead, and it will be harder to clean up later.

The proposed usage (at least what we did in the second patch and what
I did in IEEE 802.15.4 tty driver) is to use this device pointer to
set up parent node for all devices created on top of given tty port.

> I think I'd much rather see this set when the tty is created and always
> available. That would also let the whole tty layer use dev_err() and
> friends usefully ?

I was afraid of messing with tty layer in such way, as it's a bit too
complex for me.

Do you mean adding struct device pointer to struct tty_struct (easy),
or refactoring code so, that struct tty_struct contains embedded
struct device and uses it for refcounting & stuff?

--
With best wishes
Dmitry

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Alan Cox on
> I was afraid of messing with tty layer in such way, as it's a bit too
> complex for me.
>
> Do you mean adding struct device pointer to struct tty_struct (easy),
> or refactoring code so, that struct tty_struct contains embedded
> struct device and uses it for refcounting & stuff?

The former.

Alan
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/