Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: storage: add a macro for the upper limit of max LUN

The meaning of this value is already used in several places,
but with constant values and comments to explain it separately.
It's better to have a central place to do this then use the macro
in those places for better readability.

Signed-off-by: Dingyan Li <18500469033@163.com>
Reviewed-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://lore.kernel.org/r/20241030083858.46907-1-18500469033@163.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Dingyan Li and committed by
Greg Kroah-Hartman
d8d936c5 3b56774f

+13 -13
+2 -6
drivers/usb/gadget/function/f_tcm.c
··· 441 441 pr_err("No LUNs configured?\n"); 442 442 return -EINVAL; 443 443 } 444 - /* 445 - * If 4 LUNs are present we return 3 i.e. LUN 0..3 can be 446 - * accessed. The upper limit is 0xf 447 - */ 448 444 luns--; 449 - if (luns > 0xf) { 445 + if (luns > US_BULK_MAX_LUN_LIMIT) { 450 446 pr_info_once("Limiting the number of luns to 16\n"); 451 - luns = 0xf; 447 + luns = US_BULK_MAX_LUN_LIMIT; 452 448 } 453 449 ret_lun = cdev->req->buf; 454 450 *ret_lun = luns;
+1 -1
drivers/usb/gadget/function/storage_common.h
··· 131 131 #define FSG_BUFLEN ((u32)16384) 132 132 133 133 /* Maximal number of LUNs supported in mass storage function */ 134 - #define FSG_MAX_LUNS 16 134 + #define FSG_MAX_LUNS (US_BULK_MAX_LUN_LIMIT + 1) 135 135 136 136 enum fsg_buffer_state { 137 137 BUF_STATE_SENDING = -2,
+2 -6
drivers/usb/storage/transport.c
··· 1087 1087 usb_stor_dbg(us, "GetMaxLUN command result is %d, data is %d\n", 1088 1088 result, us->iobuf[0]); 1089 1089 1090 - /* 1091 - * If we have a successful request, return the result if valid. The 1092 - * CBW LUN field is 4 bits wide, so the value reported by the device 1093 - * should fit into that. 1094 - */ 1090 + /* If we have a successful request, return the result if valid. */ 1095 1091 if (result > 0) { 1096 - if (us->iobuf[0] < 16) { 1092 + if (us->iobuf[0] <= US_BULK_MAX_LUN_LIMIT) { 1097 1093 return us->iobuf[0]; 1098 1094 } else { 1099 1095 dev_info(&us->pusb_intf->dev,
+8
include/linux/usb/storage.h
··· 82 82 #define US_BULK_RESET_REQUEST 0xff 83 83 #define US_BULK_GET_MAX_LUN 0xfe 84 84 85 + /* 86 + * If 4 LUNs are supported then the LUNs would be 87 + * numbered from 0 to 3, and the return value for 88 + * US_BULK_GET_MAX_LUN request would be 3. The valid 89 + * LUN field is 4 bits wide, the upper limit is 0x0f. 90 + */ 91 + #define US_BULK_MAX_LUN_LIMIT 0x0f 92 + 85 93 #endif