diff mbox series

[3/6] hvcs: Remove sysfs group earlier

Message ID 20230201195743.303163-4-brking@linux.vnet.ibm.com (mailing list archive)
State Handled Elsewhere
Headers show
Series hvcs: Various hvcs device hotplug fixes | expand

Commit Message

Brian King Feb. 1, 2023, 7:57 p.m. UTC
Cleanup the sysfs group earlier in remove. This eliminates
errors coming from kernfs when attempting to remove a console
device that is in use.

Signed-off-by: Brian King <brking@linux.vnet.ibm.com>
---
 drivers/tty/hvc/hvcs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Greg KH Feb. 1, 2023, 8:04 p.m. UTC | #1
On Wed, Feb 01, 2023 at 01:57:40PM -0600, Brian King wrote:
> Cleanup the sysfs group earlier in remove. This eliminates
> errors coming from kernfs when attempting to remove a console
> device that is in use.
> 
> Signed-off-by: Brian King <brking@linux.vnet.ibm.com>
> ---
>  drivers/tty/hvc/hvcs.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
> index 9131dcb2e8d8..9c5887d0c882 100644
> --- a/drivers/tty/hvc/hvcs.c
> +++ b/drivers/tty/hvc/hvcs.c
> @@ -688,8 +688,6 @@ static void hvcs_destruct_port(struct tty_port *p)
>  	spin_unlock_irqrestore(&hvcsd->lock, flags);
>  	spin_unlock(&hvcs_structs_lock);
>  
> -	sysfs_remove_group(&vdev->dev.kobj, &hvcs_attr_group);
> -
>  	kfree(hvcsd);
>  }
>  
> @@ -814,6 +812,8 @@ static void hvcs_remove(struct vio_dev *dev)
>  	 */
>  	tty_port_put(&hvcsd->port);
>  
> +	sysfs_remove_group(&dev->dev.kobj, &hvcs_attr_group);
> +

Why is this needed at all?  The files should be auto-removed when the
device is removed, right?

And calling sysfs_*() functions from a driver is a huge hint that
something is wrong here.  Worst case, this should be calling
device_remove_group(), but really, the default groups pointer should be
set and then you don't have to add/remove anything, it will all happen
automatically for you by the driver core at the properly place and time.

Can you do that instead of this change?  That should fix it all up
properly.

thanks,

greg k-h
diff mbox series

Patch

diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
index 9131dcb2e8d8..9c5887d0c882 100644
--- a/drivers/tty/hvc/hvcs.c
+++ b/drivers/tty/hvc/hvcs.c
@@ -688,8 +688,6 @@  static void hvcs_destruct_port(struct tty_port *p)
 	spin_unlock_irqrestore(&hvcsd->lock, flags);
 	spin_unlock(&hvcs_structs_lock);
 
-	sysfs_remove_group(&vdev->dev.kobj, &hvcs_attr_group);
-
 	kfree(hvcsd);
 }
 
@@ -814,6 +812,8 @@  static void hvcs_remove(struct vio_dev *dev)
 	 */
 	tty_port_put(&hvcsd->port);
 
+	sysfs_remove_group(&dev->dev.kobj, &hvcs_attr_group);
+
 	/*
 	 * The hangup is a scheduled function which will auto chain call
 	 * hvcs_hangup.  The tty should always be valid at this time unless a