From: Jiri Slaby <jslaby@suse.cz>
To: NeilBrown <neil@brown.name>, Mark Rutland <mark.rutland@arm.com>,
One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk>,
Peter Hurley <peter@hurleysoftware.com>,
Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Sebastian Reichel <sre@kernel.org>, Pavel Machek <pavel@ucw.cz>,
Grant Likely <grant.likely@linaro.org>
Cc: GTA04 owners <gta04-owner@goldelico.com>,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] TTY: add support for tty_slave devices.
Date: Tue, 24 Mar 2015 11:31:55 +0100 [thread overview]
Message-ID: <55113D1B.1030906@suse.cz> (raw)
In-Reply-To: <20150318055831.21025.85317.stgit@notabene.brown>
Hi,
On 03/18/2015, 06:58 AM, NeilBrown wrote:
> --- /dev/null
> +++ b/drivers/tty/slave/tty_slave_core.c
> @@ -0,0 +1,136 @@
...
> +static int tty_slave_match(struct device *dev, struct device_driver *drv)
> +{
> + return of_driver_match_device(dev, drv);
> +}
> +
> +static void tty_slave_release(struct device *dev)
> +{
> + kfree(dev);
This should free the slave where the dev is contained. This is never
called IMO due to missing put_device's in the code.
> +}
> +
> +struct bus_type tty_slave_bus_type = {
> + .name = "tty-slave",
> + .match = tty_slave_match,
> +};
> +
> +int tty_slave_register(struct device *parent, struct device_node *node,
> + struct device *tty, struct tty_driver *drv)
> +{
> + struct tty_slave *slave;
> + int retval;
> +
> + if (!of_get_property(node, "compatible", NULL))
> + return -ENODEV;
> +
> + slave = kzalloc(sizeof(*slave), GFP_KERNEL);
> + if (!slave)
> + return -ENOMEM;
> +
device_initialize();
> + slave->dev.bus = &tty_slave_bus_type;
> + slave->dev.parent = parent;
> + slave->dev.release = tty_slave_release;
> + slave->dev.of_node = of_node_get(node);
> + dev_set_name(&slave->dev, "%s", node->name);
> + slave->tty_dev = tty;
> + slave->tty_drv = drv;
> + slave->ops = *drv->ops;
> + retval = device_register(&slave->dev);
> + if (retval) {
> + of_node_put(node);
> + kfree(slave);
Do device_put() instead of the two. And do the two in .release.
> + }
> + return retval;
> +}
> +EXPORT_SYMBOL(tty_slave_register);
...
> --- a/drivers/tty/tty_io.c
> +++ b/drivers/tty/tty_io.c
...
> @@ -3205,6 +3208,29 @@ static void tty_device_create_release(struct device *dev)
> kfree(dev);
> }
>
> +int tty_register_finalize(struct tty_driver *driver, struct device *dev)
> +{
> + int retval;
> + bool cdev = false;
> + int index = dev->devt - MKDEV(driver->major,
> + driver->minor_start);
> + printk("REGISTER %d %d 0x%x %d\n", driver->major, driver->minor_start, dev->devt, index);
> + if (!(driver->flags & TTY_DRIVER_DYNAMIC_ALLOC)) {
> + retval = tty_cdev_add(driver,
> + dev->devt,
> + index, 1);
> + if (retval)
> + return retval;
> + cdev = true;
> + }
> + retval = device_register(dev);
> + if (retval == 0)
> + return 0;
> + if (cdev)
> + cdev_del(&driver->cdevs[index]);
> + return retval;
> +}
> +EXPORT_SYMBOL(tty_register_finalize);
> /**
> * tty_register_device_attr - register a tty device
> * @driver: the tty driver that describes the tty device
> @@ -3234,7 +3260,8 @@ struct device *tty_register_device_attr(struct tty_driver *driver,
> dev_t devt = MKDEV(driver->major, driver->minor_start) + index;
> struct device *dev = NULL;
> int retval = -ENODEV;
> - bool cdev = false;
> + struct device_node *node;
> + bool slave_registered = false;
>
> if (index >= driver->num) {
> printk(KERN_ERR "Attempt to register invalid tty line number "
> @@ -3247,13 +3274,6 @@ struct device *tty_register_device_attr(struct tty_driver *driver,
> else
> tty_line_name(driver, index, name);
>
> - if (!(driver->flags & TTY_DRIVER_DYNAMIC_ALLOC)) {
> - retval = tty_cdev_add(driver, devt, index, 1);
> - if (retval)
> - goto error;
> - cdev = true;
> - }
> -
> dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> if (!dev) {
> retval = -ENOMEM;
> @@ -3268,16 +3288,24 @@ struct device *tty_register_device_attr(struct tty_driver *driver,
> dev->groups = attr_grp;
> dev_set_drvdata(dev, drvdata);
>
> - retval = device_register(dev);
> - if (retval)
> - goto error;
> + if (device && device->of_node)
> + for_each_available_child_of_node(device->of_node, node) {
> + if (tty_slave_register(device, node, dev, driver) == 0)
> + slave_registered = true;
> + if (slave_registered)
> + break;
> + }
> +
> + if (!slave_registered) {
> + retval = tty_register_finalize(driver, dev);
> + if (retval)
> + goto error;
> + }
>
> return dev;
And what about ttys not using the tty_register_device* helpers?
What happens when the tty is unregistered?
> --- /dev/null
> +++ b/include/linux/tty_slave.h
> @@ -0,0 +1,26 @@
> +
> +struct tty_slave {
> + struct device *tty_dev;
> + struct tty_driver *tty_drv;
> + struct tty_operations ops;
> + struct device dev;
> +};
> +
> +int tty_slave_finalize(struct tty_slave *slave);
> +int tty_slave_driver_register(struct device_driver *drv);
> +#if config_enabled(CONFIG_TTY_SLAVE)
Since TTY_SLAVE is tristate, this will work only for TTY_SLAVE == y, not
m. Use IS_ENABLED instead.
> +void tty_slave_activate(struct tty_struct *tty);
> +int tty_slave_register(struct device *parent, struct device_node *node,
> + struct device *tty, struct tty_driver *drv);
> +#else
> +static inline void tty_slave_activate(struct tty_struct *tty)
> +{
> +}
> +static inline int tty_slave_register(struct device *parent,
> + struct device_node *node,
> + struct device *tty,
> + struct tty_driver *drv)
> +{
> + return -ENODEV;
> +}
> +#endif
thanks,
--
js
suse labs
next prev parent reply other threads:[~2015-03-24 10:31 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-18 5:58 [PATCH 0/3] tty slave device support - version 3 NeilBrown
2015-03-18 5:58 ` [PATCH 3/3] tty/slaves: add a driver to power on/off UART attached devices NeilBrown
[not found] ` <20150318055831.21025.33670.stgit-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2015-03-20 7:54 ` [Gta04-owner] " Dr. H. Nikolaus Schaller
[not found] ` <C53A3E5D-5AEA-4F0F-88A9-F9BC8CB0D0D6-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2015-03-20 8:54 ` NeilBrown
2015-03-20 9:34 ` Dr. H. Nikolaus Schaller
[not found] ` <14FB51CF-9568-4BF4-B917-2C019D992FDB-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2015-03-20 19:50 ` Pavel Machek
2015-03-20 23:31 ` NeilBrown
2015-03-24 17:58 ` Dr. H. Nikolaus Schaller
2015-03-25 1:45 ` Sebastian Reichel
2015-03-25 7:59 ` Dr. H. Nikolaus Schaller
2015-03-25 15:21 ` Sebastian Reichel
2015-03-25 16:44 ` Dr. H. Nikolaus Schaller
2015-03-26 18:08 ` Sebastian Reichel
2015-03-27 9:22 ` Dr. H. Nikolaus Schaller
2015-03-27 16:31 ` Sebastian Reichel
2015-03-27 17:11 ` Dr. H. Nikolaus Schaller
2015-04-27 20:35 ` Pavel Machek
2015-04-29 6:56 ` Dr. H. Nikolaus Schaller
2015-03-25 20:53 ` Pavel Machek
2015-03-25 21:25 ` Dr. H. Nikolaus Schaller
[not found] ` <1F3B5E32-1330-457C-AE25-791319293C38-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2015-03-26 5:56 ` Pavel Machek
2015-03-26 6:44 ` Dr. H. Nikolaus Schaller
[not found] ` <365B2C25-1782-4ADE-B620-190A4CC5E8E3-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2015-04-04 7:52 ` Pavel Machek
2015-03-25 20:42 ` Pavel Machek
2015-03-25 21:22 ` Dr. H. Nikolaus Schaller
2015-03-18 5:58 ` [PATCH 1/3] TTY: use class_find_device to find port in uart_suspend/resume NeilBrown
[not found] ` <20150318055831.21025.27864.stgit-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2015-03-25 16:20 ` Peter Hurley
2015-03-29 21:49 ` [Gta04-owner] " NeilBrown
2015-03-18 5:58 ` [PATCH 2/3] TTY: add support for tty_slave devices NeilBrown
2015-03-18 9:11 ` Paul Bolle
2015-03-22 3:32 ` NeilBrown
2015-03-20 19:41 ` Pavel Machek
2015-03-22 3:42 ` [Gta04-owner] " NeilBrown
[not found] ` <20150322144209.14abc603-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2015-03-22 7:58 ` Pavel Machek
2015-03-24 10:31 ` Jiri Slaby [this message]
2015-03-30 23:45 ` NeilBrown
2015-03-25 16:30 ` Peter Hurley
2015-03-25 21:17 ` [Gta04-owner] " NeilBrown
2015-03-27 11:09 ` Peter Hurley
2015-03-31 0:33 ` NeilBrown
2015-03-20 7:54 ` [Gta04-owner] [PATCH 0/3] tty slave device support - version 3 Dr. H. Nikolaus Schaller
[not found] ` <80D7E742-4633-4CCD-B754-221387D82922-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2015-03-20 8:43 ` NeilBrown
2015-03-20 8:54 ` Dr. H. Nikolaus Schaller
2015-03-20 13:08 ` Sebastian Reichel
2015-03-20 13:57 ` Dr. H. Nikolaus Schaller
[not found] ` <72268D51-F993-497A-B4F9-707C8DB7155C-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2015-03-20 17:14 ` Sebastian Reichel
2015-03-20 19:31 ` Pavel Machek
[not found] ` <20150318055437.21025.13990.stgit-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2015-05-05 19:54 ` Peter Hurley
2015-05-05 20:46 ` NeilBrown
[not found] ` <55492001.30806-WaGBZJeGNqdsbIuE7sb01tBPR1lH4CV8@public.gmane.org>
2015-05-06 5:19 ` [Gta04-owner] " Dr. H. Nikolaus Schaller
[not found] ` <DE60E7AA-1BF4-4A68-9638-E09F85FD5C72-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2015-05-06 9:27 ` Pavel Machek
2015-05-06 11:50 ` Dr. H. Nikolaus Schaller
2015-05-06 12:05 ` Peter Hurley
2015-05-06 12:27 ` Dr. H. Nikolaus Schaller
2015-05-06 12:36 ` Mark Rutland
2015-05-06 13:28 ` Dr. H. Nikolaus Schaller
2015-05-06 14:15 ` Mark Rutland
2015-05-06 16:09 ` Dr. H. Nikolaus Schaller
2015-05-06 17:18 ` Mark Rutland
2015-05-07 12:46 ` Dr. H. Nikolaus Schaller
2015-05-07 14:30 ` Peter Hurley
2015-05-07 15:11 ` Dr. H. Nikolaus Schaller
2015-05-07 16:18 ` Peter Hurley
2015-05-07 16:57 ` Dr. H. Nikolaus Schaller
[not found] ` <B4D487C5-C260-497B-A441-6C381D53616C-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2015-05-07 14:56 ` Peter Hurley
[not found] ` <554B7D33.602-WaGBZJeGNqdsbIuE7sb01tBPR1lH4CV8@public.gmane.org>
2015-05-07 15:34 ` Dr. H. Nikolaus Schaller
2015-05-07 15:51 ` Peter Hurley
2015-05-07 16:46 ` Dr. H. Nikolaus Schaller
2015-05-13 8:09 ` Dr. H. Nikolaus Schaller
2015-06-03 11:49 ` [PATCH RFC 0/3] UART slave device support Dr. H. Nikolaus Schaller
[not found] ` <56C579D3-E8F8-4B5A-B6E8-993B113F3461-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2015-06-06 13:09 ` Pavel Machek
[not found] ` <463356C5-E3C6-432C-A1C5-71F0287F1FEE@goldelico.com>
2015-06-03 12:09 ` [Gta04-owner] [PATCH RFC 3/3] misc: Add w2g0004 gps receiver driver Christ van Willegen
2015-05-07 15:37 ` [Gta04-owner] [PATCH 0/3] tty slave device support - version 3 Peter Hurley
[not found] ` <A2594559-CA92-40C2-A06A-AC2483E85CB1-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2015-05-06 14:28 ` Pavel Machek
2015-05-06 16:12 ` Dr. H. Nikolaus Schaller
[not found] ` <C68A105A-7147-4143-9B91-1A239726A780-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2015-06-06 13:09 ` Pavel Machek
2015-06-06 18:53 ` Belisko Marek
2015-06-06 18:55 ` Belisko Marek
2015-05-07 15:48 ` Rob Herring
2015-05-06 11:10 ` Peter Hurley
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=55113D1B.1030906@suse.cz \
--to=jslaby@suse.cz \
--cc=arnd@arndb.de \
--cc=devicetree@vger.kernel.org \
--cc=gnomes@lxorguk.ukuu.org.uk \
--cc=grant.likely@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=gta04-owner@goldelico.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=neil@brown.name \
--cc=pavel@ucw.cz \
--cc=peter@hurleysoftware.com \
--cc=sre@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;
as well as URLs for NNTP newsgroup(s).