[PATCH 0/3] tty: some cleanups in remove functions

STALE2020d

8 messages, 3 authors, 2021-01-20 · open the first message on its own page

[PATCH 0/3] tty: some cleanups in remove functions

From: Uwe Kleine-König <hidden>
Date: 2021-01-14 17:59:22

Hello,

while working on changing the prototype of struct vio_driver::remove to
return void I noticed a few exit paths in such callbacks that return an
error code.

This is a bad thing because the return value is ignored (which is the
motivation to make it void) and the corresponding device then ends in
some limbo state.

Luckily for the three offenders here these cases cannot happen and are
simplified accordingly. This then makes the patch that changes the
remove callback's prototype simpler because it only changes prototypes
and drops "return 0"s.

Best regards and thanks for considering,
Uwe Kleine-König

Uwe Kleine-König (3):
  tty: hvcs: Drop unnecessary if block
  tty: vcc: Drop unnecessary if block
  tty: vcc: Drop impossible to hit WARN_ON

 drivers/tty/hvc/hvcs.c |  3 ---
 drivers/tty/vcc.c      | 10 ++--------
 2 files changed, 2 insertions(+), 11 deletions(-)

-- 
2.29.2

[PATCH 3/3] tty: vcc: Drop impossible to hit WARN_ON

From: Uwe Kleine-König <hidden>
Date: 2021-01-14 17:58:51

vcc_get() returns the port that has provided port->index. As the port that
is about to be removed isn't removed yet this trivially will find this
port. So simplify the call to not assign an identical value to the port
pointer and drop the warning that is never hit.

Signed-off-by: Uwe Kleine-König <redacted>
---
 drivers/tty/vcc.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/tty/vcc.c b/drivers/tty/vcc.c
index d9b0dc6deae9..e2d6205f83ce 100644
--- a/drivers/tty/vcc.c
+++ b/drivers/tty/vcc.c
@@ -692,12 +692,9 @@ static int vcc_remove(struct vio_dev *vdev)
 		tty_vhangup(port->tty);
 
 	/* Get exclusive reference to VCC, ensures that there are no other
-	 * clients to this port
+	 * clients to this port. This cannot fail.
 	 */
-	port = vcc_get(port->index, true);
-
-	if (WARN_ON(!port))
-		return -ENODEV;
+	vcc_get(port->index, true);
 
 	tty_unregister_device(vcc_tty_driver, port->index);
 
-- 
2.29.2

Re: [PATCH 3/3] tty: vcc: Drop impossible to hit WARN_ON

From: Jiri Slaby <jirislaby@kernel.org>
Date: 2021-01-15 08:21:45

On 14. 01. 21, 18:57, Uwe Kleine-König wrote:
vcc_get() returns the port that has provided port->index. As the port that
is about to be removed isn't removed yet this trivially will find this
port. So simplify the call to not assign an identical value to the port
pointer and drop the warning that is never hit.

Signed-off-by: Uwe Kleine-König <redacted>
Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
quoted hunk
---
  drivers/tty/vcc.c | 7 ++-----
  1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/tty/vcc.c b/drivers/tty/vcc.c
index d9b0dc6deae9..e2d6205f83ce 100644
--- a/drivers/tty/vcc.c
+++ b/drivers/tty/vcc.c
@@ -692,12 +692,9 @@ static int vcc_remove(struct vio_dev *vdev)
  		tty_vhangup(port->tty);
  
  	/* Get exclusive reference to VCC, ensures that there are no other
-	 * clients to this port
+	 * clients to this port. This cannot fail.
  	 */
-	port = vcc_get(port->index, true);
-
-	if (WARN_ON(!port))
-		return -ENODEV;
+	vcc_get(port->index, true);
  
  	tty_unregister_device(vcc_tty_driver, port->index);
  

-- 
js

[PATCH 1/3] tty: hvcs: Drop unnecessary if block

From: Uwe Kleine-König <hidden>
Date: 2021-01-14 17:59:22

If hvcs_probe() succeeded dev_set_drvdata() is called with a non-NULL
value, and if hvcs_probe() failed hvcs_remove() isn't called.

So there is no way dev_get_drvdata() can return NULL in hvcs_remove() and
the check can just go away.

Signed-off-by: Uwe Kleine-König <redacted>
---
 drivers/tty/hvc/hvcs.c | 3 ---
 1 file changed, 3 deletions(-)
diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
index 509d1042825a..3e0461285c34 100644
--- a/drivers/tty/hvc/hvcs.c
+++ b/drivers/tty/hvc/hvcs.c
@@ -825,9 +825,6 @@ static int hvcs_remove(struct vio_dev *dev)
 	unsigned long flags;
 	struct tty_struct *tty;
 
-	if (!hvcsd)
-		return -ENODEV;
-
 	/* By this time the vty-server won't be getting any more interrupts */
 
 	spin_lock_irqsave(&hvcsd->lock, flags);
-- 
2.29.2

Re: [PATCH 1/3] tty: hvcs: Drop unnecessary if block

From: Jiri Slaby <jirislaby@kernel.org>
Date: 2021-01-15 08:20:41

On 14. 01. 21, 18:57, Uwe Kleine-König wrote:
If hvcs_probe() succeeded dev_set_drvdata() is called with a non-NULL
value, and if hvcs_probe() failed hvcs_remove() isn't called.

So there is no way dev_get_drvdata() can return NULL in hvcs_remove() and
the check can just go away.

Signed-off-by: Uwe Kleine-König <redacted>
Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
quoted hunk
---
  drivers/tty/hvc/hvcs.c | 3 ---
  1 file changed, 3 deletions(-)
diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
index 509d1042825a..3e0461285c34 100644
--- a/drivers/tty/hvc/hvcs.c
+++ b/drivers/tty/hvc/hvcs.c
@@ -825,9 +825,6 @@ static int hvcs_remove(struct vio_dev *dev)
  	unsigned long flags;
  	struct tty_struct *tty;
  
-	if (!hvcsd)
-		return -ENODEV;
-
  	/* By this time the vty-server won't be getting any more interrupts */
  
  	spin_lock_irqsave(&hvcsd->lock, flags);

-- 
js

Re: [PATCH 1/3] tty: hvcs: Drop unnecessary if block

From: Tyrel Datwyler <tyreld@linux.ibm.com>
Date: 2021-01-20 17:18:27

On 1/14/21 9:57 AM, Uwe Kleine-König wrote:
If hvcs_probe() succeeded dev_set_drvdata() is called with a non-NULL
value, and if hvcs_probe() failed hvcs_remove() isn't called.

So there is no way dev_get_drvdata() can return NULL in hvcs_remove() and
the check can just go away.

Signed-off-by: Uwe Kleine-König <redacted>
Reviewed-by: Tyrel Datwyler <tyreld@linux.ibm.com>
quoted hunk
---
 drivers/tty/hvc/hvcs.c | 3 ---
 1 file changed, 3 deletions(-)
diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
index 509d1042825a..3e0461285c34 100644
--- a/drivers/tty/hvc/hvcs.c
+++ b/drivers/tty/hvc/hvcs.c
@@ -825,9 +825,6 @@ static int hvcs_remove(struct vio_dev *dev)
 	unsigned long flags;
 	struct tty_struct *tty;

-	if (!hvcsd)
-		return -ENODEV;
-
 	/* By this time the vty-server won't be getting any more interrupts */

 	spin_lock_irqsave(&hvcsd->lock, flags);

[PATCH 2/3] tty: vcc: Drop unnecessary if block

From: Uwe Kleine-König <hidden>
Date: 2021-01-14 17:59:22

If vcc_probe() succeeded dev_set_drvdata() is called with a non-NULL
value, and if vcc_probe() failed vcc_remove() isn't called.

So there is no way dev_get_drvdata() can return NULL in vcc_remove() and
the check can just go away.

Signed-off-by: Uwe Kleine-König <redacted>
---
 drivers/tty/vcc.c | 3 ---
 1 file changed, 3 deletions(-)
diff --git a/drivers/tty/vcc.c b/drivers/tty/vcc.c
index 9ffd42e333b8..d9b0dc6deae9 100644
--- a/drivers/tty/vcc.c
+++ b/drivers/tty/vcc.c
@@ -681,9 +681,6 @@ static int vcc_remove(struct vio_dev *vdev)
 {
 	struct vcc_port *port = dev_get_drvdata(&vdev->dev);
 
-	if (!port)
-		return -ENODEV;
-
 	del_timer_sync(&port->rx_timer);
 	del_timer_sync(&port->tx_timer);
 
-- 
2.29.2

Re: [PATCH 2/3] tty: vcc: Drop unnecessary if block

From: Jiri Slaby <jirislaby@kernel.org>
Date: 2021-01-15 08:21:25

On 14. 01. 21, 18:57, Uwe Kleine-König wrote:
If vcc_probe() succeeded dev_set_drvdata() is called with a non-NULL
value, and if vcc_probe() failed vcc_remove() isn't called.

So there is no way dev_get_drvdata() can return NULL in vcc_remove() and
the check can just go away.

Signed-off-by: Uwe Kleine-König <redacted>
Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
quoted hunk
---
  drivers/tty/vcc.c | 3 ---
  1 file changed, 3 deletions(-)
diff --git a/drivers/tty/vcc.c b/drivers/tty/vcc.c
index 9ffd42e333b8..d9b0dc6deae9 100644
--- a/drivers/tty/vcc.c
+++ b/drivers/tty/vcc.c
@@ -681,9 +681,6 @@ static int vcc_remove(struct vio_dev *vdev)
  {
  	struct vcc_port *port = dev_get_drvdata(&vdev->dev);
  
-	if (!port)
-		return -ENODEV;
-
  	del_timer_sync(&port->rx_timer);
  	del_timer_sync(&port->tx_timer);
  

-- 
js
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help