From: NeilBrown <neil@brown.name>
To: 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>,
Rob Herring <robherring2@gmail.com>, Pavel Machek <pavel@ucw.cz>,
Grant Likely <grant.likely@linaro.org>,
Jiri Slaby <jslaby@suse.cz>
Cc: GTA04 owners <gta04-owner@goldelico.com>,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/4] TTY: split tty_register_device_attr into 'initialize' and 'add' parts.
Date: Mon, 11 May 2015 11:56:14 +1000 [thread overview]
Message-ID: <20150511015614.5709.7959.stgit@notabene.brown> (raw)
In-Reply-To: <20150511013540.5709.93626.stgit@notabene.brown>
This provides seperate
tty_device_initialize_attr()
and
tty_device_add_attr()
similar to device_initialize() and device_add().
Similiarly tty_port_initialize_device_attr() is added to match
tty_port_register_device_attr().
It will allow a client to separate initalization and adding of the
device.
Signed-off-by: NeilBrown <neil@brown.name>
---
drivers/tty/tty_io.c | 102 +++++++++++++++++++++++++++++++++---------------
drivers/tty/tty_port.c | 24 +++++++++++
include/linux/tty.h | 9 ++++
3 files changed, 104 insertions(+), 31 deletions(-)
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index ccb99b772965..83ca25b9c2da 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -3205,8 +3205,29 @@ static void tty_device_create_release(struct device *dev)
kfree(dev);
}
+int tty_device_add(struct tty_driver *driver, struct device *dev)
+{
+ int retval;
+ bool cdev = false;
+ int index = dev->devt - MKDEV(driver->major,
+ driver->minor_start);
+
+ if (!(driver->flags & TTY_DRIVER_DYNAMIC_ALLOC)) {
+ retval = tty_cdev_add(driver, dev->devt, index, 1);
+ if (retval)
+ return retval;
+ cdev = true;
+ }
+ retval = device_add(dev);
+ if (retval == 0)
+ return 0;
+ if (cdev)
+ cdev_del(&driver->cdevs[index]);
+ return retval;
+}
+EXPORT_SYMBOL(tty_device_add);
/**
- * tty_register_device_attr - register a tty device
+ * tty_device_initialize_attr - initialize a tty device, but don't 'add'
* @driver: the tty driver that describes the tty device
* @index: the index in the tty driver for this tty device
* @device: a struct device that is associated with this tty device.
@@ -3218,23 +3239,19 @@ static void tty_device_create_release(struct device *dev)
* Returns a pointer to the struct device for this tty device
* (or ERR_PTR(-EFOO) on error).
*
- * This call is required to be made to register an individual tty device
- * if the tty driver's flags have the TTY_DRIVER_DYNAMIC_DEV bit set. If
- * that bit is not set, this function should not be called by a tty
- * driver.
+ * tty_device_add() must be called after this call returns successfully
+ * before the device will be full registered and available.
*
* Locking: ??
*/
-struct device *tty_register_device_attr(struct tty_driver *driver,
- unsigned index, struct device *device,
- void *drvdata,
- const struct attribute_group **attr_grp)
+struct device *tty_device_initialize_attr(struct tty_driver *driver,
+ unsigned index, struct device *device,
+ void *drvdata,
+ const struct attribute_group **attr_grp)
{
char name[64];
dev_t devt = MKDEV(driver->major, driver->minor_start) + index;
struct device *dev = NULL;
- int retval = -ENODEV;
- bool cdev = false;
if (index >= driver->num) {
printk(KERN_ERR "Attempt to register invalid tty line number "
@@ -3247,19 +3264,11 @@ 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;
- goto error;
- }
+ if (!dev)
+ return ERR_PTR(-ENOMEM);
+ device_initialize(dev);
dev->devt = devt;
dev->class = tty_class;
dev->parent = device;
@@ -3268,17 +3277,48 @@ 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;
-
return dev;
+}
+EXPORT_SYMBOL_GPL(tty_device_initialize_attr);
-error:
- put_device(dev);
- if (cdev)
- cdev_del(&driver->cdevs[index]);
- return ERR_PTR(retval);
+/**
+ * tty_register_device_attr - register a tty device
+ * @driver: the tty driver that describes the tty device
+ * @index: the index in the tty driver for this tty device
+ * @device: a struct device that is associated with this tty device.
+ * This field is optional, if there is no known struct device
+ * for this tty device it can be set to NULL safely.
+ * @drvdata: Driver data to be set to device.
+ * @attr_grp: Attribute group to be set on device.
+ *
+ * Returns a pointer to the struct device for this tty device
+ * (or ERR_PTR(-EFOO) on error).
+ *
+ * This call is required to be made to register an individual tty device
+ * if the tty driver's flags have the TTY_DRIVER_DYNAMIC_DEV bit set. If
+ * that bit is not set, this function should not be called by a tty
+ * driver.
+ *
+ * Locking: ??
+ */
+struct device *tty_register_device_attr(struct tty_driver *driver,
+ unsigned index, struct device *device,
+ void *drvdata,
+ const struct attribute_group **attr_grp)
+{
+ struct device *dev;
+ int ret;
+
+ dev = tty_device_initialize_attr(driver, index, device,
+ drvdata, attr_grp);
+ if (IS_ERR(dev))
+ return dev;
+ ret = tty_device_add(driver, dev);
+ if (ret) {
+ put_device(dev);
+ return ERR_PTR(ret);
+ }
+ return dev;
}
EXPORT_SYMBOL_GPL(tty_register_device_attr);
diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index 40b31835f80b..f4145c0f1f45 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -97,6 +97,30 @@ struct device *tty_port_register_device_attr(struct tty_port *port,
}
EXPORT_SYMBOL_GPL(tty_port_register_device_attr);
+/**
+ * tty_port_initialize_device_attr - initialize tty device
+ * @port: tty_port of the device
+ * @driver: tty_driver for this device
+ * @index: index of the tty
+ * @device: parent if exists, otherwise NULL
+ * @drvdata: Driver data to be set to device.
+ * @attr_grp: Attribute group to be set on device.
+ *
+ * It is the same as tty_initialize_device_attr except the provided @port is
+ * linked to a concrete tty specified by @index. Use this or tty_port_install
+ * (or both). Call tty_port_link_device as a last resort.
+ */
+struct device *tty_port_initialize_device_attr(struct tty_port *port,
+ struct tty_driver *driver, unsigned index,
+ struct device *device, void *drvdata,
+ const struct attribute_group **attr_grp)
+{
+ tty_port_link_device(port, driver, index);
+ return tty_device_initialize_attr(driver, index, device, drvdata,
+ attr_grp);
+}
+EXPORT_SYMBOL_GPL(tty_port_initialize_device_attr);
+
int tty_port_alloc_xmit_buf(struct tty_port *port)
{
/* We may sleep in get_zeroed_page() */
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 04d5f1213700..1b371ba9ed09 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -436,6 +436,11 @@ extern struct device *tty_register_device_attr(struct tty_driver *driver,
unsigned index, struct device *device,
void *drvdata,
const struct attribute_group **attr_grp);
+extern struct device *tty_device_initialize_attr(struct tty_driver *driver,
+ unsigned index, struct device *device,
+ void *drvdata,
+ const struct attribute_group **attr_grp);
+extern int tty_device_add(struct tty_driver *driver, struct device *dev);
extern void tty_unregister_device(struct tty_driver *driver, unsigned index);
extern int tty_read_raw_data(struct tty_struct *tty, unsigned char *bufp,
int buflen);
@@ -534,6 +539,10 @@ extern struct device *tty_port_register_device_attr(struct tty_port *port,
struct tty_driver *driver, unsigned index,
struct device *device, void *drvdata,
const struct attribute_group **attr_grp);
+extern struct device *tty_port_initialize_device_attr(struct tty_port *port,
+ struct tty_driver *driver, unsigned index,
+ struct device *device, void *drvdata,
+ const struct attribute_group **attr_grp);
extern int tty_port_alloc_xmit_buf(struct tty_port *port);
extern void tty_port_free_xmit_buf(struct tty_port *port);
extern void tty_port_destroy(struct tty_port *port);
next prev parent reply other threads:[~2015-05-11 1:56 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-11 1:56 [PATCH 0/4] UART slave device support - version 4 NeilBrown
2015-05-11 1:56 ` NeilBrown [this message]
2015-05-11 1:56 ` [PATCH 3/4] TTY: add support for uart_slave devices NeilBrown
2015-05-12 8:31 ` Paul Bolle
2015-05-12 23:35 ` NeilBrown
2015-05-11 1:56 ` [PATCH 1/4] TTY: use class_find_device to find port in uart_suspend/resume NeilBrown
[not found] ` <20150511013540.5709.93626.stgit-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2015-05-11 1:56 ` [PATCH 4/4] tty/slaves: add a driver to power on/off UART attached devices NeilBrown
2015-08-07 13:01 ` [PATCH 0/4] UART slave device support - version 4 Linus Walleij
2015-08-11 23:20 ` NeilBrown
2015-08-28 5:52 ` [Gta04-owner] " Dr. H. Nikolaus Schaller
[not found] ` <CD86D8CD-20D8-44EF-8245-A3E49C2D3EA7-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2015-08-28 7:02 ` Pavel Machek
2015-08-28 9:43 ` Dr. H. Nikolaus Schaller
[not found] ` <0579762D-51C2-45F0-A362-EE31215A40E8-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2015-08-28 11:04 ` Pavel Machek
2015-08-28 20:04 ` Christ van Willegen
2016-01-12 13:06 ` Tomeu Vizoso
2016-01-12 13:28 ` [Gta04-owner] " H. Nikolaus Schaller
2016-01-13 19:15 ` Mark Rutland
2016-01-15 9:34 ` H. Nikolaus Schaller
2016-01-15 11:01 ` Mark Rutland
2016-01-15 15:05 ` H. Nikolaus Schaller
[not found] ` <69F8E1E5-EF49-4C8E-88E9-973F82F7102E-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2016-01-15 15:43 ` Andrey Vostrikov
2016-01-15 16:08 ` H. Nikolaus Schaller
[not found] ` <CB69F6F0-B40B-47D1-B175-8401F43288C5-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2016-01-15 17:16 ` Peter Hurley
[not found] ` <56992959.2020204-WaGBZJeGNqdsbIuE7sb01tBPR1lH4CV8@public.gmane.org>
2016-01-15 17:32 ` H. Nikolaus Schaller
2016-01-15 17:43 ` Peter Hurley
2016-01-15 17:58 ` H. Nikolaus Schaller
[not found] ` <69FAE2F5-25D1-4E5E-9FED-FC86773269D6-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2016-01-15 19:23 ` Peter Hurley
2016-01-15 21:24 ` H. Nikolaus Schaller
2016-01-15 22:40 ` Rob Herring
[not found] ` <CAL_JsqL=Wotz4FuoV7PULfZNfSV=S_q0iOzkckVA3NDDzMdfZQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-01-16 7:34 ` Vostrikov Andrey
2016-01-16 23:31 ` Rob Herring
2016-01-17 8:53 ` H. Nikolaus Schaller
[not found] ` <3D5F35D7-31B5-4E68-875F-7DD492EF0316-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2016-01-17 14:19 ` One Thousand Gnomes
2016-01-17 17:57 ` H. Nikolaus Schaller
[not found] ` <1D5F146E-D347-453B-9158-8D269F8DA99C-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2016-01-17 19:38 ` One Thousand Gnomes
2016-01-18 8:17 ` H. Nikolaus Schaller
[not found] ` <37DCE36D-0A5E-41C5-BDA4-857DCF9F2DD1-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2016-01-18 8:56 ` Andrey Vostrikov
2016-01-18 11:52 ` H. Nikolaus Schaller
2016-01-18 11:19 ` One Thousand Gnomes
[not found] ` <20160118111926.0882b422@ lxorguk.ukuu.org.uk>
[not found] ` <20160118111926.0882b422-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2016-01-18 20:58 ` H. Nikolaus Schaller
[not found] ` <07F3B6C0-0C87-478C-B6DD-5C0EECB42D0D-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2016-01-18 22:03 ` One Thousand Gnomes
[not found] ` <20160118220319.051c9cc0-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2016-01-18 22:32 ` H. Nikolaus Schaller
[not found] ` <C1E6AFE7-1EF2-4C70-8BE2-82F5CD7DDE22-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2016-01-19 14:25 ` One Thousand Gnomes
[not found] ` <20160119142542.5bf64395-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2016-01-20 17:33 ` H. Nikolaus Schaller
2016-01-20 16:11 ` H. Nikolaus Schaller
[not found] ` <9E37C552-361C-4A54-980E-E3BFFF834302-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2016-01-20 17:46 ` One Thousand Gnomes
[not found] ` <20160120174610.1c64239a-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2016-01-20 18:03 ` H. Nikolaus Schaller
2016-01-21 10:01 ` Radek Polak
[not found] ` <39B850CE-E381-4D3B-BD0A-84AFE7DAEEDF-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2016-01-22 15:45 ` Tomeu Vizoso
2016-01-22 16:49 ` Rob Herring
[not found] ` <CAAObsKB4oFeM9Cjet5z+vz0S1M8RZ3jFt03b38KXq+sh6f5EwA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-01-22 20:12 ` One Thousand Gnomes
[not found] ` <20160122201229.5df0bb2d-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2016-01-23 7:40 ` Andreas Kemnade
2016-01-23 12:19 ` H. Nikolaus Schaller
[not found] ` <DF404071-9FD0-4B33-B1B5-EC14192655E7-xXXSsgcRVICgSpxsJD1C4w@public.gmane.org>
2016-01-23 17:28 ` One Thousand Gnomes
2016-01-23 22:04 ` H. Nikolaus Schaller
2016-01-24 17:10 ` One Thousand Gnomes
2016-01-25 10:36 ` H. Nikolaus Schaller
2016-01-19 6:32 ` Andreas Kemnade
[not found] ` <744620565.20160116103445-M4DtvfQ/ZS1MRgGoP+s0PdBPR1lH4CV8@public.gmane.org>
2016-01-20 19:38 ` Dmitry Torokhov
[not found] ` <CAKdAkRQh7xSgOXERhA8EjXEfX5m-PTTjiv757X7FYxK=bhfpww-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-01-20 20:09 ` Vostrikov Andrey
2016-01-15 16:12 ` Mark Rutland
2016-01-15 19:16 ` H. Nikolaus Schaller
2016-01-15 19:40 ` Pavel Machek
2016-01-15 20:35 ` H. Nikolaus Schaller
[not found] ` <CAAObsKD7-02HVUosXVwqcH6HyGEGYJ9jdNepuNhLiiL+ujO5iw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-01-12 21:28 ` NeilBrown
[not found] ` <87lh7u8p3b.fsf-wvvUuzkyo1HefUI2i7LXDhCRmIWqnp/j@public.gmane.org>
2016-01-13 19:00 ` Pavel Machek
2015-05-31 22:01 ` Greg Kroah-Hartman
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=20150511015614.5709.7959.stgit@notabene.brown \
--to=neil@brown.name \
--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=jslaby@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=pavel@ucw.cz \
--cc=peter@hurleysoftware.com \
--cc=robherring2@gmail.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).