linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] parport: daisy: avoid hardcoded name
@ 2019-10-16 14:45 Sudip Mukherjee
  2019-10-16 14:45 ` [PATCH 2/4] parport: do not check portlist when using device-model Sudip Mukherjee
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Sudip Mukherjee @ 2019-10-16 14:45 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, Michal Kubecek, Steven Rostedt, Sudip Mukherjee

The daisy device name is hardcoded, define it in the header file and
use it in the code.

Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
---
 drivers/parport/probe.c | 2 +-
 include/linux/parport.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/parport/probe.c b/drivers/parport/probe.c
index e035174ba205..4e2bfeb6b4a6 100644
--- a/drivers/parport/probe.c
+++ b/drivers/parport/probe.c
@@ -257,7 +257,7 @@ static ssize_t parport_read_device_id (struct parport *port, char *buffer,
 ssize_t parport_device_id (int devnum, char *buffer, size_t count)
 {
 	ssize_t retval = -ENXIO;
-	struct pardevice *dev = parport_open (devnum, "Device ID probe");
+	struct pardevice *dev = parport_open(devnum, daisy_dev_name);
 	if (!dev)
 		return -ENXIO;
 
diff --git a/include/linux/parport.h b/include/linux/parport.h
index 397607a0c0eb..13932ce8b37b 100644
--- a/include/linux/parport.h
+++ b/include/linux/parport.h
@@ -460,6 +460,7 @@ extern size_t parport_ieee1284_epp_read_addr (struct parport *,
 					      void *, size_t, int);
 
 /* IEEE1284.3 functions */
+#define daisy_dev_name "Device ID probe"
 extern int parport_daisy_init (struct parport *port);
 extern void parport_daisy_fini (struct parport *port);
 extern struct pardevice *parport_open (int devnum, const char *name);
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] parport: do not check portlist when using device-model
  2019-10-16 14:45 [PATCH 1/4] parport: daisy: avoid hardcoded name Sudip Mukherjee
@ 2019-10-16 14:45 ` Sudip Mukherjee
  2019-10-16 14:45 ` [PATCH 3/4] parport: load lowlevel driver if ports not found Sudip Mukherjee
  2019-10-16 14:45 ` [PATCH 4/4] parport: daisy: use new parport device model Sudip Mukherjee
  2 siblings, 0 replies; 6+ messages in thread
From: Sudip Mukherjee @ 2019-10-16 14:45 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, Michal Kubecek, Steven Rostedt, Sudip Mukherjee

We do not need to maintain a list of ports when we are using the
device-model. The base layer is going to maintain the list for us and
we can get the list of ports just using bus_for_each_dev().

Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
---
 drivers/parport/share.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/parport/share.c b/drivers/parport/share.c
index 7b4ee33c1935..96538b7975e5 100644
--- a/drivers/parport/share.c
+++ b/drivers/parport/share.c
@@ -266,9 +266,6 @@ static int port_check(struct device *dev, void *dev_drv)
 int __parport_register_driver(struct parport_driver *drv, struct module *owner,
 			      const char *mod_name)
 {
-	if (list_empty(&portlist))
-		get_lowlevel_driver();
-
 	if (drv->devmodel) {
 		/* using device model */
 		int ret;
@@ -292,6 +289,8 @@ int __parport_register_driver(struct parport_driver *drv, struct module *owner,
 
 		drv->devmodel = false;
 
+		if (list_empty(&portlist))
+			get_lowlevel_driver();
 		mutex_lock(&registration_lock);
 		list_for_each_entry(port, &portlist, list)
 			drv->attach(port);
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] parport: load lowlevel driver if ports not found
  2019-10-16 14:45 [PATCH 1/4] parport: daisy: avoid hardcoded name Sudip Mukherjee
  2019-10-16 14:45 ` [PATCH 2/4] parport: do not check portlist when using device-model Sudip Mukherjee
@ 2019-10-16 14:45 ` Sudip Mukherjee
  2019-10-16 14:45 ` [PATCH 4/4] parport: daisy: use new parport device model Sudip Mukherjee
  2 siblings, 0 replies; 6+ messages in thread
From: Sudip Mukherjee @ 2019-10-16 14:45 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, Michal Kubecek, Steven Rostedt, Sudip Mukherjee

Usually all the distro will load the parport low level driver as part
of their initialization. But we can get into a situation where all the
parallel port drivers are built as module and we unload all the modules
at a later time. Then if we just do "modprobe parport" it will only
load the parport module and will not load the low level driver which
will actually register the ports. So, check the bus if there is any
parport registered, if not, load the low level driver.

We can get into the above situation with all distro but only Suse has
setup the alias for "parport_lowlevel" and so it only works in Suse.
Users of Debian based distro will need to load the lowlevel module
manually.

Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
---
 drivers/parport/share.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/parport/share.c b/drivers/parport/share.c
index 96538b7975e5..d6920ebeabcd 100644
--- a/drivers/parport/share.c
+++ b/drivers/parport/share.c
@@ -230,6 +230,18 @@ static int port_check(struct device *dev, void *dev_drv)
 	return 0;
 }
 
+/*
+ * Iterates through all the devices connected to the bus and return 1
+ * if the device is a parallel port.
+ */
+
+static int port_detect(struct device *dev, void *dev_drv)
+{
+	if (is_parport(dev))
+		return 1;
+	return 0;
+}
+
 /**
  *	parport_register_driver - register a parallel port device driver
  *	@drv: structure describing the driver
@@ -279,6 +291,15 @@ int __parport_register_driver(struct parport_driver *drv, struct module *owner,
 		if (ret)
 			return ret;
 
+		/*
+		 * check if bus has any parallel port registered, if
+		 * none is found then load the lowlevel driver.
+		 */
+		ret = bus_for_each_dev(&parport_bus_type, NULL, NULL,
+				       port_detect);
+		if (!ret)
+			get_lowlevel_driver();
+
 		mutex_lock(&registration_lock);
 		if (drv->match_port)
 			bus_for_each_dev(&parport_bus_type, NULL, drv,
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] parport: daisy: use new parport device model
  2019-10-16 14:45 [PATCH 1/4] parport: daisy: avoid hardcoded name Sudip Mukherjee
  2019-10-16 14:45 ` [PATCH 2/4] parport: do not check portlist when using device-model Sudip Mukherjee
  2019-10-16 14:45 ` [PATCH 3/4] parport: load lowlevel driver if ports not found Sudip Mukherjee
@ 2019-10-16 14:45 ` Sudip Mukherjee
  2019-10-18  1:10   ` Steven Rostedt
  2 siblings, 1 reply; 6+ messages in thread
From: Sudip Mukherjee @ 2019-10-16 14:45 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, Michal Kubecek, Steven Rostedt, Sudip Mukherjee

Modify parport daisy driver to use the new parallel port device model.

Last attempt was '1aec4211204d ("parport: daisy: use new parport device
model")' which failed as daisy was also trying to load the low level
driver and that resulted in a deadlock.

Cc: Michal Kubecek <mkubecek@suse.cz>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
---

Steven, Michal,
Can you please test this series in your test environment and verify that
I am not breaking anything this time.

 drivers/parport/daisy.c | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/drivers/parport/daisy.c b/drivers/parport/daisy.c
index 5484a46dafda..95b5c3363582 100644
--- a/drivers/parport/daisy.c
+++ b/drivers/parport/daisy.c
@@ -45,6 +45,7 @@ static struct daisydev {
 static DEFINE_SPINLOCK(topology_lock);
 
 static int numdevs;
+static bool daisy_init_done;
 
 /* Forward-declaration of lower-level functions. */
 static int mux_present(struct parport *port);
@@ -87,6 +88,24 @@ static struct parport *clone_parport(struct parport *real, int muxport)
 	return extra;
 }
 
+static int daisy_drv_probe(struct pardevice *par_dev)
+{
+	struct device_driver *drv = par_dev->dev.driver;
+
+	if (strcmp(drv->name, "daisy_drv"))
+		return -ENODEV;
+	if (strcmp(par_dev->name, daisy_dev_name))
+		return -ENODEV;
+
+	return 0;
+}
+
+static struct parport_driver daisy_driver = {
+	.name = "daisy_drv",
+	.probe = daisy_drv_probe,
+	.devmodel = true,
+};
+
 /* Discover the IEEE1284.3 topology on a port -- muxes and daisy chains.
  * Return value is number of devices actually detected. */
 int parport_daisy_init(struct parport *port)
@@ -98,6 +117,23 @@ int parport_daisy_init(struct parport *port)
 	int i;
 	int last_try = 0;
 
+	if (!daisy_init_done) {
+		/*
+		 * flag should be marked true first as
+		 * parport_register_driver() might try to load the low
+		 * level driver which will lead to announcing new ports
+		 * and which will again come back here at
+		 * parport_daisy_init()
+		 */
+		daisy_init_done = true;
+		i = parport_register_driver(&daisy_driver);
+		if (i) {
+			pr_err("daisy registration failed\n");
+			daisy_init_done = false;
+			return i;
+		}
+	}
+
 again:
 	/* Because this is called before any other devices exist,
 	 * we don't have to claim exclusive access.  */
@@ -213,10 +249,12 @@ void parport_daisy_fini(struct parport *port)
 struct pardevice *parport_open(int devnum, const char *name)
 {
 	struct daisydev *p = topology;
+	struct pardev_cb par_cb;
 	struct parport *port;
 	struct pardevice *dev;
 	int daisy;
 
+	memset(&par_cb, 0, sizeof(par_cb));
 	spin_lock(&topology_lock);
 	while (p && p->devnum != devnum)
 		p = p->next;
@@ -230,7 +268,7 @@ struct pardevice *parport_open(int devnum, const char *name)
 	port = parport_get_port(p->port);
 	spin_unlock(&topology_lock);
 
-	dev = parport_register_device(port, name, NULL, NULL, NULL, 0, NULL);
+	dev = parport_register_dev_model(port, name, &par_cb, devnum);
 	parport_put_port(port);
 	if (!dev)
 		return NULL;
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 4/4] parport: daisy: use new parport device model
  2019-10-16 14:45 ` [PATCH 4/4] parport: daisy: use new parport device model Sudip Mukherjee
@ 2019-10-18  1:10   ` Steven Rostedt
  2019-11-11 15:43     ` Sudip Mukherjee
  0 siblings, 1 reply; 6+ messages in thread
From: Steven Rostedt @ 2019-10-18  1:10 UTC (permalink / raw)
  To: Sudip Mukherjee; +Cc: Greg Kroah-Hartman, linux-kernel, Michal Kubecek

On Wed, 16 Oct 2019 15:45:40 +0100
Sudip Mukherjee <sudipm.mukherjee@gmail.com> wrote:

> Modify parport daisy driver to use the new parallel port device model.
> 
> Last attempt was '1aec4211204d ("parport: daisy: use new parport device
> model")' which failed as daisy was also trying to load the low level
> driver and that resulted in a deadlock.
> 
> Cc: Michal Kubecek <mkubecek@suse.cz>
> Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
> Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
> ---
> 
> Steven, Michal,
> Can you please test this series in your test environment and verify that
> I am not breaking anything this time.
> 
>

I checked out 1aec4211204d~1 (just before the broken commit), and
applied these four patches. It booted with the config that wouldn't
boot with the broken commit.

Tested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

-- Steve

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 4/4] parport: daisy: use new parport device model
  2019-10-18  1:10   ` Steven Rostedt
@ 2019-11-11 15:43     ` Sudip Mukherjee
  0 siblings, 0 replies; 6+ messages in thread
From: Sudip Mukherjee @ 2019-11-11 15:43 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-kernel, Michal Kubecek, Steven Rostedt

Hi Greg,

On Fri, Oct 18, 2019 at 2:10 AM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Wed, 16 Oct 2019 15:45:40 +0100
> Sudip Mukherjee <sudipm.mukherjee@gmail.com> wrote:
>
> > Modify parport daisy driver to use the new parallel port device model.
> >
> > Last attempt was '1aec4211204d ("parport: daisy: use new parport device
> > model")' which failed as daisy was also trying to load the low level
> > driver and that resulted in a deadlock.
> >
> > Cc: Michal Kubecek <mkubecek@suse.cz>
> > Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
> > Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
> > ---
> >
> > Steven, Michal,
> > Can you please test this series in your test environment and verify that
> > I am not breaking anything this time.
> >
> >
>
> I checked out 1aec4211204d~1 (just before the broken commit), and
> applied these four patches. It booted with the config that wouldn't
> boot with the broken commit.
>
> Tested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

A gentle ping on this series.


-- 
Regards
Sudip

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-11-11 15:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-16 14:45 [PATCH 1/4] parport: daisy: avoid hardcoded name Sudip Mukherjee
2019-10-16 14:45 ` [PATCH 2/4] parport: do not check portlist when using device-model Sudip Mukherjee
2019-10-16 14:45 ` [PATCH 3/4] parport: load lowlevel driver if ports not found Sudip Mukherjee
2019-10-16 14:45 ` [PATCH 4/4] parport: daisy: use new parport device model Sudip Mukherjee
2019-10-18  1:10   ` Steven Rostedt
2019-11-11 15:43     ` Sudip Mukherjee

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).