public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] staging: greybus: uart: fix style issues
@ 2026-02-25 18:38 Shubham Chakraborty
  2026-02-25 18:38 ` [PATCH 2/2] staging: greybus: uart: convert to XArray Shubham Chakraborty
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Shubham Chakraborty @ 2026-02-25 18:38 UTC (permalink / raw)
  To: David Lin, Johan Hovold, Alex Elder, Greg Kroah-Hartman
  Cc: greybus-dev, linux-staging, linux-kernel, Shubham Chakraborty

Fix checkpatch.pl warnings by adding comments to mutex and spinlocks,
and fixing alignment to match open parenthesis.

Signed-off-by: Shubham Chakraborty <chakrabortyshubham66@gmail.com>
---
 drivers/staging/greybus/uart.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index 7d060b4cd33d..1d2c4ef70865 100644
--- a/drivers/staging/greybus/uart.c
+++ b/drivers/staging/greybus/uart.c
@@ -50,12 +50,12 @@ struct gb_tty {
 	unsigned int minor;
 	unsigned char clocal;
 	bool disconnected;
-	spinlock_t read_lock;
-	spinlock_t write_lock;
+	spinlock_t read_lock;		/* protects read operations */
+	spinlock_t write_lock;		/* protects write operations */
 	struct async_icount iocount;
 	struct async_icount oldcount;
 	wait_queue_head_t wioctl;
-	struct mutex mutex;
+	struct mutex mutex;		/* serializes port operations */
 	u8 ctrlin;	/* input control lines */
 	u8 ctrlout;	/* output control lines */
 	struct gb_uart_set_line_coding_request line_coding;
@@ -318,7 +318,7 @@ static int gb_uart_wait_for_all_credits(struct gb_tty *gb_tty)
 		return 0;
 
 	ret = wait_for_completion_timeout(&gb_tty->credits_complete,
-			msecs_to_jiffies(GB_UART_CREDIT_WAIT_TIMEOUT_MSEC));
+					  msecs_to_jiffies(GB_UART_CREDIT_WAIT_TIMEOUT_MSEC));
 	if (!ret) {
 		dev_err(&gb_tty->gbphy_dev->dev,
 			"time out waiting for credits\n");
-- 
2.53.0


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

* [PATCH 2/2] staging: greybus: uart: convert to XArray
  2026-02-25 18:38 [PATCH 1/2] staging: greybus: uart: fix style issues Shubham Chakraborty
@ 2026-02-25 18:38 ` Shubham Chakraborty
  2026-02-25 18:47   ` Greg Kroah-Hartman
  2026-02-25 18:43 ` [PATCH 1/2] staging: greybus: uart: fix style issues Greg Kroah-Hartman
  2026-02-26  7:59 ` Dan Carpenter
  2 siblings, 1 reply; 10+ messages in thread
From: Shubham Chakraborty @ 2026-02-25 18:38 UTC (permalink / raw)
  To: David Lin, Johan Hovold, Alex Elder, Greg Kroah-Hartman
  Cc: greybus-dev, linux-staging, linux-kernel, Shubham Chakraborty

Replace the deprecated IDR API with the more modern XArray API.
This simplifies the code and improves efficiency.

Signed-off-by: Shubham Chakraborty <chakrabortyshubham66@gmail.com>
---
 drivers/staging/greybus/uart.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index 1d2c4ef70865..fe554eba555a 100644
--- a/drivers/staging/greybus/uart.c
+++ b/drivers/staging/greybus/uart.c
@@ -67,7 +67,7 @@ struct gb_tty {
 };
 
 static struct tty_driver *gb_tty_driver;
-static DEFINE_IDR(tty_minors);
+static DEFINE_XARRAY(tty_minors);
 static DEFINE_MUTEX(table_lock);
 
 static int gb_uart_receive_data_handler(struct gb_operation *op)
@@ -342,7 +342,7 @@ static struct gb_tty *get_gb_by_minor(unsigned int minor)
 	struct gb_tty *gb_tty;
 
 	mutex_lock(&table_lock);
-	gb_tty = idr_find(&tty_minors, minor);
+	gb_tty = xa_load(&tty_minors, minor);
 	if (gb_tty) {
 		mutex_lock(&gb_tty->mutex);
 		if (gb_tty->disconnected) {
@@ -359,14 +359,18 @@ static struct gb_tty *get_gb_by_minor(unsigned int minor)
 
 static int alloc_minor(struct gb_tty *gb_tty)
 {
-	int minor;
+	u32 minor;
+	int ret;
 
 	mutex_lock(&table_lock);
-	minor = idr_alloc(&tty_minors, gb_tty, 0, GB_NUM_MINORS, GFP_KERNEL);
+	ret = xa_alloc(&tty_minors, &minor, gb_tty,
+		       XA_LIMIT(0, GB_NUM_MINORS - 1), GFP_KERNEL);
 	mutex_unlock(&table_lock);
-	if (minor >= 0)
+	if (ret >= 0) {
 		gb_tty->minor = minor;
-	return minor;
+		return minor;
+	}
+	return ret;
 }
 
 static void release_minor(struct gb_tty *gb_tty)
@@ -375,7 +379,7 @@ static void release_minor(struct gb_tty *gb_tty)
 
 	gb_tty->minor = 0;	/* Maybe should use an invalid value instead */
 	mutex_lock(&table_lock);
-	idr_remove(&tty_minors, minor);
+	xa_erase(&tty_minors, minor);
 	mutex_unlock(&table_lock);
 }
 
@@ -984,7 +988,7 @@ static void gb_tty_exit(void)
 {
 	tty_unregister_driver(gb_tty_driver);
 	tty_driver_kref_put(gb_tty_driver);
-	idr_destroy(&tty_minors);
+	xa_destroy(&tty_minors);
 }
 
 static const struct gbphy_device_id gb_uart_id_table[] = {
-- 
2.53.0


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

* Re: [PATCH 1/2] staging: greybus: uart: fix style issues
  2026-02-25 18:38 [PATCH 1/2] staging: greybus: uart: fix style issues Shubham Chakraborty
  2026-02-25 18:38 ` [PATCH 2/2] staging: greybus: uart: convert to XArray Shubham Chakraborty
@ 2026-02-25 18:43 ` Greg Kroah-Hartman
  2026-02-26  7:59 ` Dan Carpenter
  2 siblings, 0 replies; 10+ messages in thread
From: Greg Kroah-Hartman @ 2026-02-25 18:43 UTC (permalink / raw)
  To: Shubham Chakraborty
  Cc: David Lin, Johan Hovold, Alex Elder, greybus-dev, linux-staging,
	linux-kernel

On Thu, Feb 26, 2026 at 12:08:35AM +0530, Shubham Chakraborty wrote:
> Fix checkpatch.pl warnings by adding comments to mutex and spinlocks,
> and fixing alignment to match open parenthesis.
> 
> Signed-off-by: Shubham Chakraborty <chakrabortyshubham66@gmail.com>
> ---
>  drivers/staging/greybus/uart.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
> index 7d060b4cd33d..1d2c4ef70865 100644
> --- a/drivers/staging/greybus/uart.c
> +++ b/drivers/staging/greybus/uart.c
> @@ -50,12 +50,12 @@ struct gb_tty {
>  	unsigned int minor;
>  	unsigned char clocal;
>  	bool disconnected;
> -	spinlock_t read_lock;
> -	spinlock_t write_lock;
> +	spinlock_t read_lock;		/* protects read operations */
> +	spinlock_t write_lock;		/* protects write operations */
>  	struct async_icount iocount;
>  	struct async_icount oldcount;
>  	wait_queue_head_t wioctl;
> -	struct mutex mutex;
> +	struct mutex mutex;		/* serializes port operations */
>  	u8 ctrlin;	/* input control lines */
>  	u8 ctrlout;	/* output control lines */
>  	struct gb_uart_set_line_coding_request line_coding;
> @@ -318,7 +318,7 @@ static int gb_uart_wait_for_all_credits(struct gb_tty *gb_tty)
>  		return 0;
>  
>  	ret = wait_for_completion_timeout(&gb_tty->credits_complete,
> -			msecs_to_jiffies(GB_UART_CREDIT_WAIT_TIMEOUT_MSEC));
> +					  msecs_to_jiffies(GB_UART_CREDIT_WAIT_TIMEOUT_MSEC));
>  	if (!ret) {
>  		dev_err(&gb_tty->gbphy_dev->dev,
>  			"time out waiting for credits\n");
> -- 
> 2.53.0
> 

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
a patch that has triggered this response.  He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created.  Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.

You are receiving this message because of the following common error(s)
as indicated below:

- Your patch did many different things all at once, making it difficult
  to review.  All Linux kernel patches need to only do one thing at a
  time.  If you need to do multiple things (such as clean up all coding
  style issues in a file/driver), do it in a sequence of patches, each
  one doing only one thing.  This will make it easier to review the
  patches to ensure that they are correct, and to help alleviate any
  merge issues that larger patches can cause.

- You sent a patch that has been sent multiple times in the past few
  days, and is identical to ones that has been recently rejected.
  Please always look at the mailing list traffic to determine if you are
  duplicating other people's work.

If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.

thanks,

greg k-h's patch email bot

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

* Re: [PATCH 2/2] staging: greybus: uart: convert to XArray
  2026-02-25 18:38 ` [PATCH 2/2] staging: greybus: uart: convert to XArray Shubham Chakraborty
@ 2026-02-25 18:47   ` Greg Kroah-Hartman
  2026-02-26 18:25     ` Shubham Chakraborty
  0 siblings, 1 reply; 10+ messages in thread
From: Greg Kroah-Hartman @ 2026-02-25 18:47 UTC (permalink / raw)
  To: Shubham Chakraborty
  Cc: David Lin, Johan Hovold, Alex Elder, greybus-dev, linux-staging,
	linux-kernel

On Thu, Feb 26, 2026 at 12:08:36AM +0530, Shubham Chakraborty wrote:
> Replace the deprecated IDR API with the more modern XArray API.
> This simplifies the code and improves efficiency.
> 
> Signed-off-by: Shubham Chakraborty <chakrabortyshubham66@gmail.com>
> ---
>  drivers/staging/greybus/uart.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)

This really isn't needed, sorry, it doesn't improve any "efficiency" and
I think I've rejected this change in the past as well.

It's just a simple minor number, an idr is just fine for it.

thanks,

greg k-h

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

* Re: [PATCH 1/2] staging: greybus: uart: fix style issues
  2026-02-25 18:38 [PATCH 1/2] staging: greybus: uart: fix style issues Shubham Chakraborty
  2026-02-25 18:38 ` [PATCH 2/2] staging: greybus: uart: convert to XArray Shubham Chakraborty
  2026-02-25 18:43 ` [PATCH 1/2] staging: greybus: uart: fix style issues Greg Kroah-Hartman
@ 2026-02-26  7:59 ` Dan Carpenter
  2026-02-26 17:58   ` Shubham Chakraborty
  2026-02-27  6:52   ` [PATCH v2] staging: greybus: uart: add descriptive lock comments Shubham Chakraborty
  2 siblings, 2 replies; 10+ messages in thread
From: Dan Carpenter @ 2026-02-26  7:59 UTC (permalink / raw)
  To: Shubham Chakraborty
  Cc: David Lin, Johan Hovold, Alex Elder, Greg Kroah-Hartman,
	greybus-dev, linux-staging, linux-kernel

On Thu, Feb 26, 2026 at 12:08:35AM +0530, Shubham Chakraborty wrote:
> Fix checkpatch.pl warnings by adding comments to mutex and spinlocks,
> and fixing alignment to match open parenthesis.
> 
> Signed-off-by: Shubham Chakraborty <chakrabortyshubham66@gmail.com>
> ---
>  drivers/staging/greybus/uart.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
> index 7d060b4cd33d..1d2c4ef70865 100644
> --- a/drivers/staging/greybus/uart.c
> +++ b/drivers/staging/greybus/uart.c
> @@ -50,12 +50,12 @@ struct gb_tty {
>  	unsigned int minor;
>  	unsigned char clocal;
>  	bool disconnected;
> -	spinlock_t read_lock;
> -	spinlock_t write_lock;
> +	spinlock_t read_lock;		/* protects read operations */

This is really vague, but I wouldn't say it was accurate.

> +	spinlock_t write_lock;		/* protects write operations */

Also really vague.  What does "operations" mean in this context?
But word "write" is correct at least.

>  	struct async_icount iocount;
>  	struct async_icount oldcount;
>  	wait_queue_head_t wioctl;
> -	struct mutex mutex;
> +	struct mutex mutex;		/* serializes port operations */

This comment is doesn't really add any value.

regards,
dan carpenter


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

* Re: [PATCH 1/2] staging: greybus: uart: fix style issues
  2026-02-26  7:59 ` Dan Carpenter
@ 2026-02-26 17:58   ` Shubham Chakraborty
  2026-02-27  6:52   ` [PATCH v2] staging: greybus: uart: add descriptive lock comments Shubham Chakraborty
  1 sibling, 0 replies; 10+ messages in thread
From: Shubham Chakraborty @ 2026-02-26 17:58 UTC (permalink / raw)
  To: dan.carpenter
  Cc: dtwlin, johan, elder, gregkh, greybus-dev, linux-staging,
	linux-kernel

Hi Dan,
Thanks for the review.
You're right, the comments are too vague and don't add much value.
I'll review what the locks actually protect and resend with more
specific documentation, or drop the patch if it doesn't improve clarity.

Thanks,
Shubham

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

* Re: [PATCH 2/2] staging: greybus: uart: convert to XArray
  2026-02-25 18:47   ` Greg Kroah-Hartman
@ 2026-02-26 18:25     ` Shubham Chakraborty
  0 siblings, 0 replies; 10+ messages in thread
From: Shubham Chakraborty @ 2026-02-26 18:25 UTC (permalink / raw)
  To: gregkh
  Cc: chakrabortyshubham66, dtwlin, johan, elder, greybus-dev,
	linux-staging, linux-kernel

Understood, I'll drop this patch. Thanks for the review.

Regards,
Shubham Chakraborty

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

* [PATCH v2] staging: greybus: uart: add descriptive lock comments
  2026-02-26  7:59 ` Dan Carpenter
  2026-02-26 17:58   ` Shubham Chakraborty
@ 2026-02-27  6:52   ` Shubham Chakraborty
  2026-02-27  9:03     ` Dan Carpenter
  1 sibling, 1 reply; 10+ messages in thread
From: Shubham Chakraborty @ 2026-02-27  6:52 UTC (permalink / raw)
  To: gregkh
  Cc: dan.carpenter, dtwlin, johan, elder, greybus-dev, linux-staging,
	linux-kernel, Shubham Chakraborty

Replace vague lock comments with specific descriptions of
what data each lock protects:
- read_lock: protects iocount and oldcount
- write_lock: protects write_fifo and credits
- mutex: protects disconnected state

Signed-off-by: Shubham Chakraborty <chakrabortyshubham66@gmail.com>
---
 drivers/staging/greybus/uart.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index fe554eba555a..1e51818e34a8 100644
--- a/drivers/staging/greybus/uart.c
+++ b/drivers/staging/greybus/uart.c
@@ -50,12 +50,12 @@ struct gb_tty {
 	unsigned int minor;
 	unsigned char clocal;
 	bool disconnected;
-	spinlock_t read_lock;		/* protects read operations */
-	spinlock_t write_lock;		/* protects write operations */
+	spinlock_t read_lock;		/* protects iocount and oldcount */
+	spinlock_t write_lock;		/* protects write_fifo and credits */
 	struct async_icount iocount;
 	struct async_icount oldcount;
 	wait_queue_head_t wioctl;
-	struct mutex mutex;		/* serializes port operations */
+	struct mutex mutex;		/* protects disconnected state */
 	u8 ctrlin;	/* input control lines */
 	u8 ctrlout;	/* output control lines */
 	struct gb_uart_set_line_coding_request line_coding;
-- 
2.53.0


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

* Re: [PATCH v2] staging: greybus: uart: add descriptive lock comments
  2026-02-27  6:52   ` [PATCH v2] staging: greybus: uart: add descriptive lock comments Shubham Chakraborty
@ 2026-02-27  9:03     ` Dan Carpenter
  2026-02-27 15:48       ` [PATCH v2] staging: greybus: uart: improve " Shubham Chakraborty
  0 siblings, 1 reply; 10+ messages in thread
From: Dan Carpenter @ 2026-02-27  9:03 UTC (permalink / raw)
  To: Shubham Chakraborty
  Cc: gregkh, dtwlin, johan, elder, greybus-dev, linux-staging,
	linux-kernel

On Fri, Feb 27, 2026 at 12:22:20PM +0530, Shubham Chakraborty wrote:
> Replace vague lock comments with specific descriptions of
> what data each lock protects:
> - read_lock: protects iocount and oldcount
> - write_lock: protects write_fifo and credits
> - mutex: protects disconnected state
> 
> Signed-off-by: Shubham Chakraborty <chakrabortyshubham66@gmail.com>
> ---

When you're writing a v2 patch, you should first start from a fresh
kernel tree.  This v2 assumes that we applied the v1 patch.

https://staticthinking.wordpress.com/2022/07/27/how-to-send-a-v2-patch/

>  drivers/staging/greybus/uart.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
> index fe554eba555a..1e51818e34a8 100644
> --- a/drivers/staging/greybus/uart.c
> +++ b/drivers/staging/greybus/uart.c
> @@ -50,12 +50,12 @@ struct gb_tty {
>  	unsigned int minor;
>  	unsigned char clocal;
>  	bool disconnected;
> -	spinlock_t read_lock;		/* protects read operations */
> -	spinlock_t write_lock;		/* protects write operations */
> +	spinlock_t read_lock;		/* protects iocount and oldcount */
> +	spinlock_t write_lock;		/* protects write_fifo and credits */
>  	struct async_icount iocount;
>  	struct async_icount oldcount;
>  	wait_queue_head_t wioctl;
> -	struct mutex mutex;		/* serializes port operations */
> +	struct mutex mutex;		/* protects disconnected state */
>  	u8 ctrlin;	/* input control lines */


To be honest, I'm likely never going to be happy with a four word
explanation of what these locks do...  Probably a paragraph would be
better.

Don't just think about it so narrowly...  For example, does the name
read_lock make sense?  What does the word "read" have anything to do
with "iocount and oldcount"?

Why do we need two separate locks for read and write?  I understand
how write means write_fifo but why do "write_fifo and credits" go
together?  If write_lock protects credits, then why are there several
places where we access gb_tty->credits without taking the lock?

Then as you go along, you're going to notice weird things.  For
example, in set_serial_info() it allows non-admin uses to set the
close_delay and closing_wait to the existing values.  What is the
point of that?  Do other .set_serial() functions allow that?  I
haven't looked, so maybe there is a good reason!  But when you
look at this code with an open mind then you'll find all kinds of
questions like that.

What does protect really mean?  What would happen if we removed
the locking?  Is the locking even correct?  If read_lock "protects
iocount" then why do we not take it in gb_tty_get_icount()?

The locking around disconnect probably is meant to prevent a use after
free.  What are all the variables we allocate and how do we free them?
Does the disconnect process work?  Go through the probe make a list
of allocations.  When is the earliest we can call disconnect?  What
if we set ->disconnected = true but we haven't called
gb_connection_disable_rx() so we're still receiving packets?  I haven't
looked at it so I don't know!

regards,
dan carpenter

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

* Re: [PATCH v2] staging: greybus: uart: improve lock comments
  2026-02-27  9:03     ` Dan Carpenter
@ 2026-02-27 15:48       ` Shubham Chakraborty
  0 siblings, 0 replies; 10+ messages in thread
From: Shubham Chakraborty @ 2026-02-27 15:48 UTC (permalink / raw)
  To: dan.carpenter; +Cc: greybus-dev, gregkh, linux-staging, linux-kernel

Thanks for the detailed feedback. I'll do a proper audit of the
locking and the disconnect sequence before sending v3 from a fresh tree.

Regards,
Shubham Chakraborty

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

end of thread, other threads:[~2026-02-27 15:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-25 18:38 [PATCH 1/2] staging: greybus: uart: fix style issues Shubham Chakraborty
2026-02-25 18:38 ` [PATCH 2/2] staging: greybus: uart: convert to XArray Shubham Chakraborty
2026-02-25 18:47   ` Greg Kroah-Hartman
2026-02-26 18:25     ` Shubham Chakraborty
2026-02-25 18:43 ` [PATCH 1/2] staging: greybus: uart: fix style issues Greg Kroah-Hartman
2026-02-26  7:59 ` Dan Carpenter
2026-02-26 17:58   ` Shubham Chakraborty
2026-02-27  6:52   ` [PATCH v2] staging: greybus: uart: add descriptive lock comments Shubham Chakraborty
2026-02-27  9:03     ` Dan Carpenter
2026-02-27 15:48       ` [PATCH v2] staging: greybus: uart: improve " Shubham Chakraborty

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox