Re: [PATCH v3 1/7] char: xillybus: Improve control of execution flow with mutexes
From: Greg KH
Date: Fri Jul 31 2026 - 08:29:10 EST
On Fri, Jul 24, 2026 at 11:42:56AM +0200, Eli Billauer wrote:
> This commit addresses two issues by using mutexes:
>
> (1) Add a mutex to protect the fifo_buf_order global variable. The
> purpose of this variable is avoid repeated failed calls to
> __get_free_pages() for allocating FIFO memory, when the chunk
> size was too big. However, if two drivers are initialized at the
> same time, fifo_init() may run in parallel, and fifo_buf_order
> may be reduced too much. This is a far-fetched scenario, now
> completely prevented by fifo_buf_order_mutex.
>
> (2) setup_channels() acquires process_in_mutex to prevent
> process_bulk_in() from accessing the xillyusb_dev struct. With
> correctly working hardware, process_bulk_in() is never called while
> setup_channels() runs, because the device has no reason to send data
> in that phase. The mutex ensures that process_bulk_in() does not
> touch the members that setup_channels() alters.
>
> There is no similar protection for data flow in the other direction,
> because during the setup process, the only outbound data is the
> BULK endpoint used for commands, and it remains untouched after its
> initial setup.
>
> Assisted-by: Deepseek:v4-pro Kimi:K2.6 ChatGPT:GPT-5.5 Claude:Sonnet-4.6
> Signed-off-by: Eli Billauer <eli.billauer@xxxxxxxxx>
> ---
>
> Notes:
> Changes v2->v3:
> -- Add Assisted-by tag to description
>
> No change on v1->v2.
>
> drivers/char/xillybus/xillyusb.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/char/xillybus/xillyusb.c b/drivers/char/xillybus/xillyusb.c
> index 34e7ad3bcab3..a28e6416cb01 100644
> --- a/drivers/char/xillybus/xillyusb.c
> +++ b/drivers/char/xillybus/xillyusb.c
> @@ -50,6 +50,7 @@ MODULE_LICENSE("GPL v2");
> static const char xillyname[] = "xillyusb";
>
> static unsigned int fifo_buf_order;
> +static DEFINE_MUTEX(fifo_buf_order_mutex);
> static struct workqueue_struct *wakeup_wq;
>
> #define USB_VENDOR_ID_XILINX 0x03fd
> @@ -375,6 +376,8 @@ static int fifo_init(struct xillyfifo *fifo,
>
> unsigned int log2_fifo_buf_size;
>
> + guard(mutex)(&fifo_buf_order_mutex);
Sashiko rightly complains that using guard() combined with goto in this
function is ripe for disaster. Are you sure the compiler will work
properly for this?
thanks,
greg k-h