net: can: es58x: fully try proceeding with partial allocations
Subsystems (2)
PATCH 1/1 net: can: es58x: fully try proceeding with partial allocations
Since b1979778e985 ("can: etas_es58x: allow partial RX URB allocation to succeed") es58x_alloc_rx_urbs() sees a failure to allocate and submit the full number of URBs as a success and the driver will continue at reduced performance.
However, if you do so, there is no point in abandoning further allocations or submissions, just because an earlier one failed.
--- drivers/net/can/usb/etas_es58x/es58x_core.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/net/can/usb/etas_es58x/es58x_core.c +6 -5
@@ -1706,12 +1706,13 @@ static int es58x_alloc_rx_urbs(struct es58x_device *es58x_dev)u8 *buf;int i;int ret = -EINVAL ; +int allocated =0 ;for (i =0 ; i < param->rx_urb_max; i++) { ret =es58x_alloc_urb (es58x_dev, &urb, &buf, rx_buf_len,GFP_KERNEL );if (ret) -break ; +continue ; usb_fill_bulk_urb(urb, es58x_dev->udev, es58x_dev->rx_pipe, buf, rx_buf_len, es58x_read_bulk_callback,
@@ -1723,18 +1724,18 @@ static int es58x_alloc_rx_urbs(struct es58x_device *es58x_dev)usb_unanchor_urb (urb);usb_free_coherent (es58x_dev->udev, rx_buf_len, buf, urb->transfer_dma); -usb_free_urb (urb); -break ; + }else { + allocated++; }usb_free_urb (urb); } -if (i ==0 ) { +if (allocated ==0 ) {dev_err (dev,"%s: Could not setup any rx URBs\n" , __func__);return ret; }dev_dbg (dev,"%s: Allocated %d rx URBs each of size %u\n" , - __func__, i, rx_buf_len); + __func__, allocated, rx_buf_len);return 0 ; }
Signature · 1 line
2.53.0
Thanks for catching this and improving the logic. It looks correct to me.
Quoted 10 lines · Oliver Neukum
Since
b1979778e985("can:etas_es58x: allow partial RX URB allocation to succeed")es58x_alloc_rx_urbs()sees a failure to allocate and submit the full number of URBs as a success and the driver will continue at reduced performance.However, if you do so, there is no point in abandoning further allocations or submissions, just because an earlier one failed.
Fixes b1979778e985 ("can: etas_es58x: allow partial RX URB allocation to succeed")Signed-off-by Oliver Neukum <[email protected]>
Thanks. I left some minor comments, but the logic is already good. Here is my review tag in advance:
drivers/net/can/usb/etas_es58x/es58x_core.c static int es58x_alloc_rx_urbs(struct es58x_device *es58x_dev)
Quoted 9 lines
--- drivers/net/can/usb/etas_es58x/es58x_core.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)drivers/net/can/usb/etas_es58x/es58x_core.c +0
-0@@ -1706,12 +1706,13 @@ static int es58x_alloc_rx_urbs(struct es58x_device *es58x_dev)
While at it, can you fix the documentation (which was already incorrect in the last commmit)?
- * Return: zero on success, errno when any error occurs.
+ * Return: zero if one or more allocation succeeded, errno if all of
+ * them failed.
drivers/net/can/usb/etas_es58x/es58x_core.c static int es58x_alloc_rx_urbs(struct es58x_device *es58x_dev) · line 1709
Quoted 4 lines
drivers/net/can/usb/etas_es58x/es58x_core.c +1
-0u8 *buf;int i;int ret = -EINVAL ; +int allocated =0 ;
Nitpick: put allocated next to i as they are both related:
int i, allocated = 0;
or
int allocated; int i = 0;
at your convenience.
Quoted 23 lines
drivers/net/can/usb/etas_es58x/es58x_core.c +3
-4for (i =0 ; i < param->rx_urb_max; i++) { ret =es58x_alloc_urb (es58x_dev, &urb, &buf, rx_buf_len,GFP_KERNEL );if (ret) -break ; +continue ; usb_fill_bulk_urb(urb, es58x_dev->udev, es58x_dev->rx_pipe, buf, rx_buf_len, es58x_read_bulk_callback,@@ -1723,18 +1724,18 @@ static int es58x_alloc_rx_urbs(struct es58x_device *es58x_dev)usb_unanchor_urb (urb);usb_free_coherent (es58x_dev->udev, rx_buf_len, buf, urb->transfer_dma); -usb_free_urb (urb); -break ; + }else { + allocated++; }usb_free_urb (urb); } -if (i ==0 ) {
drivers/net/can/usb/etas_es58x/es58x_core.c static int es58x_alloc_rx_urbs(struct es58x_device *es58x_dev) · line 1741
Quoted 10 lines
drivers/net/can/usb/etas_es58x/es58x_core.c +2
-1+if (allocated ==0 ) {dev_err (dev,"%s: Could not setup any rx URBs\n" , __func__);return ret; }dev_dbg (dev,"%s: Allocated %d rx URBs each of size %u\n" , - __func__, i, rx_buf_len); + __func__, allocated, rx_buf_len);return 0 ; }
Yours sincerely,
Vincent Mailhol