linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] tty: some cleanups in remove functions
@ 2021-01-14 17:57 Uwe Kleine-König
  2021-01-14 17:57 ` [PATCH 1/3] tty: hvcs: Drop unnecessary if block Uwe Kleine-König
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Uwe Kleine-König @ 2021-01-14 17:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: David S . Miller, linuxppc-dev, sparclinux, linux-kernel

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


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

* [PATCH 1/3] tty: hvcs: Drop unnecessary if block
  2021-01-14 17:57 [PATCH 0/3] tty: some cleanups in remove functions Uwe Kleine-König
@ 2021-01-14 17:57 ` Uwe Kleine-König
  2021-01-15  8:19   ` Jiri Slaby
  2021-01-20 17:16   ` Tyrel Datwyler
  2021-01-14 17:57 ` [PATCH 2/3] tty: vcc: " Uwe Kleine-König
  2021-01-14 17:57 ` [PATCH 3/3] tty: vcc: Drop impossible to hit WARN_ON Uwe Kleine-König
  2 siblings, 2 replies; 8+ messages in thread
From: Uwe Kleine-König @ 2021-01-14 17:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: David S . Miller, linuxppc-dev, sparclinux, linux-kernel

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 <u.kleine-koenig@pengutronix.de>
---
 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


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

* [PATCH 2/3] tty: vcc: Drop unnecessary if block
  2021-01-14 17:57 [PATCH 0/3] tty: some cleanups in remove functions Uwe Kleine-König
  2021-01-14 17:57 ` [PATCH 1/3] tty: hvcs: Drop unnecessary if block Uwe Kleine-König
@ 2021-01-14 17:57 ` Uwe Kleine-König
  2021-01-15  8:20   ` Jiri Slaby
  2021-01-14 17:57 ` [PATCH 3/3] tty: vcc: Drop impossible to hit WARN_ON Uwe Kleine-König
  2 siblings, 1 reply; 8+ messages in thread
From: Uwe Kleine-König @ 2021-01-14 17:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: David S . Miller, linuxppc-dev, sparclinux, linux-kernel

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 <u.kleine-koenig@pengutronix.de>
---
 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


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

* [PATCH 3/3] tty: vcc: Drop impossible to hit WARN_ON
  2021-01-14 17:57 [PATCH 0/3] tty: some cleanups in remove functions Uwe Kleine-König
  2021-01-14 17:57 ` [PATCH 1/3] tty: hvcs: Drop unnecessary if block Uwe Kleine-König
  2021-01-14 17:57 ` [PATCH 2/3] tty: vcc: " Uwe Kleine-König
@ 2021-01-14 17:57 ` Uwe Kleine-König
  2021-01-15  8:20   ` Jiri Slaby
  2 siblings, 1 reply; 8+ messages in thread
From: Uwe Kleine-König @ 2021-01-14 17:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: David S . Miller, linuxppc-dev, sparclinux, linux-kernel

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 <u.kleine-koenig@pengutronix.de>
---
 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


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

* Re: [PATCH 1/3] tty: hvcs: Drop unnecessary if block
  2021-01-14 17:57 ` [PATCH 1/3] tty: hvcs: Drop unnecessary if block Uwe Kleine-König
@ 2021-01-15  8:19   ` Jiri Slaby
  2021-01-20 17:16   ` Tyrel Datwyler
  1 sibling, 0 replies; 8+ messages in thread
From: Jiri Slaby @ 2021-01-15  8:19 UTC (permalink / raw)
  To: Uwe Kleine-König, Greg Kroah-Hartman
  Cc: David S . Miller, linuxppc-dev, sparclinux, linux-kernel

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 <u.kleine-koenig@pengutronix.de>

Reviewed-by: Jiri Slaby <jirislaby@kernel.org>

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

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

* Re: [PATCH 2/3] tty: vcc: Drop unnecessary if block
  2021-01-14 17:57 ` [PATCH 2/3] tty: vcc: " Uwe Kleine-König
@ 2021-01-15  8:20   ` Jiri Slaby
  0 siblings, 0 replies; 8+ messages in thread
From: Jiri Slaby @ 2021-01-15  8:20 UTC (permalink / raw)
  To: Uwe Kleine-König, Greg Kroah-Hartman
  Cc: David S . Miller, linuxppc-dev, sparclinux, linux-kernel

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 <u.kleine-koenig@pengutronix.de>

Reviewed-by: Jiri Slaby <jirislaby@kernel.org>

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

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

* Re: [PATCH 3/3] tty: vcc: Drop impossible to hit WARN_ON
  2021-01-14 17:57 ` [PATCH 3/3] tty: vcc: Drop impossible to hit WARN_ON Uwe Kleine-König
@ 2021-01-15  8:20   ` Jiri Slaby
  0 siblings, 0 replies; 8+ messages in thread
From: Jiri Slaby @ 2021-01-15  8:20 UTC (permalink / raw)
  To: Uwe Kleine-König, Greg Kroah-Hartman
  Cc: David S . Miller, linuxppc-dev, sparclinux, linux-kernel

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 <u.kleine-koenig@pengutronix.de>

Reviewed-by: Jiri Slaby <jirislaby@kernel.org>

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

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

* Re: [PATCH 1/3] tty: hvcs: Drop unnecessary if block
  2021-01-14 17:57 ` [PATCH 1/3] tty: hvcs: Drop unnecessary if block Uwe Kleine-König
  2021-01-15  8:19   ` Jiri Slaby
@ 2021-01-20 17:16   ` Tyrel Datwyler
  1 sibling, 0 replies; 8+ messages in thread
From: Tyrel Datwyler @ 2021-01-20 17:16 UTC (permalink / raw)
  To: Uwe Kleine-König, Greg Kroah-Hartman, Jiri Slaby
  Cc: sparclinux, linuxppc-dev, David S . Miller, linux-kernel

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 <u.kleine-koenig@pengutronix.de>

Reviewed-by: Tyrel Datwyler <tyreld@linux.ibm.com>

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


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

end of thread, other threads:[~2021-01-20 17:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-14 17:57 [PATCH 0/3] tty: some cleanups in remove functions Uwe Kleine-König
2021-01-14 17:57 ` [PATCH 1/3] tty: hvcs: Drop unnecessary if block Uwe Kleine-König
2021-01-15  8:19   ` Jiri Slaby
2021-01-20 17:16   ` Tyrel Datwyler
2021-01-14 17:57 ` [PATCH 2/3] tty: vcc: " Uwe Kleine-König
2021-01-15  8:20   ` Jiri Slaby
2021-01-14 17:57 ` [PATCH 3/3] tty: vcc: Drop impossible to hit WARN_ON Uwe Kleine-König
2021-01-15  8:20   ` Jiri Slaby

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