Re: [PATCH 1/2] tty_io: add an API to get device corresponding totty_struct

From: Greg KH
Date: Fri Aug 06 2010 - 13:03:24 EST


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@xxxxxxxxx>
> ---
> 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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/