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

usb: musb: Constify struct musb_fifo_cfg

'struct musb_fifo_cfg' are not modified in these drivers.

Constifying these structures moves some data to a read-only section, so
increase overall security.

On a x86_64, with allmodconfig, as an example:
Before:
======
text data bss dec hex filename
64381 5537 202 70120 111e8 drivers/usb/musb/musb_core.o

After:
=====
text data bss dec hex filename
64957 4929 202 70088 111c8 drivers/usb/musb/musb_core.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/26e6f3e25dc8e785d0034dd7e59918e455563e60.1737234596.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Christophe JAILLET and committed by
Greg Kroah-Hartman
51333bfb 42bc7faa

+15 -15
+1 -1
Documentation/driver-api/usb/writing_musb_glue_layer.rst
··· 613 613 to bypass reading the configuration from silicon, and rely on a 614 614 hard-coded table that describes the endpoints configuration instead:: 615 615 616 - static struct musb_fifo_cfg jz4740_musb_fifo_cfg[] = { 616 + static const struct musb_fifo_cfg jz4740_musb_fifo_cfg[] = { 617 617 { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, }, 618 618 { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, }, 619 619 { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 64, },
+2 -2
drivers/usb/musb/jz4740.c
··· 59 59 return IRQ_NONE; 60 60 } 61 61 62 - static struct musb_fifo_cfg jz4740_musb_fifo_cfg[] = { 62 + static const struct musb_fifo_cfg jz4740_musb_fifo_cfg[] = { 63 63 { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, }, 64 64 { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, }, 65 65 { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 64, }, ··· 205 205 .platform_ops = &jz4740_musb_ops, 206 206 }; 207 207 208 - static struct musb_fifo_cfg jz4770_musb_fifo_cfg[] = { 208 + static const struct musb_fifo_cfg jz4770_musb_fifo_cfg[] = { 209 209 { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, }, 210 210 { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, }, 211 211 { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
+1 -1
drivers/usb/musb/mediatek.c
··· 365 365 #define MTK_MUSB_MAX_EP_NUM 8 366 366 #define MTK_MUSB_RAM_BITS 11 367 367 368 - static struct musb_fifo_cfg mtk_musb_mode_cfg[] = { 368 + static const struct musb_fifo_cfg mtk_musb_mode_cfg[] = { 369 369 { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, }, 370 370 { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, }, 371 371 { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
+1 -1
drivers/usb/musb/mpfs.c
··· 29 29 struct clk *clk; 30 30 }; 31 31 32 - static struct musb_fifo_cfg mpfs_musb_mode_cfg[] = { 32 + static const struct musb_fifo_cfg mpfs_musb_mode_cfg[] = { 33 33 { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, }, 34 34 { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, }, 35 35 { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
+7 -7
drivers/usb/musb/musb_core.c
··· 1271 1271 */ 1272 1272 1273 1273 /* mode 0 - fits in 2KB */ 1274 - static struct musb_fifo_cfg mode_0_cfg[] = { 1274 + static const struct musb_fifo_cfg mode_0_cfg[] = { 1275 1275 { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, }, 1276 1276 { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, }, 1277 1277 { .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, }, ··· 1280 1280 }; 1281 1281 1282 1282 /* mode 1 - fits in 4KB */ 1283 - static struct musb_fifo_cfg mode_1_cfg[] = { 1283 + static const struct musb_fifo_cfg mode_1_cfg[] = { 1284 1284 { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, .mode = BUF_DOUBLE, }, 1285 1285 { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, .mode = BUF_DOUBLE, }, 1286 1286 { .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, .mode = BUF_DOUBLE, }, ··· 1289 1289 }; 1290 1290 1291 1291 /* mode 2 - fits in 4KB */ 1292 - static struct musb_fifo_cfg mode_2_cfg[] = { 1292 + static const struct musb_fifo_cfg mode_2_cfg[] = { 1293 1293 { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, }, 1294 1294 { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, }, 1295 1295 { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, }, ··· 1299 1299 }; 1300 1300 1301 1301 /* mode 3 - fits in 4KB */ 1302 - static struct musb_fifo_cfg mode_3_cfg[] = { 1302 + static const struct musb_fifo_cfg mode_3_cfg[] = { 1303 1303 { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, .mode = BUF_DOUBLE, }, 1304 1304 { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, .mode = BUF_DOUBLE, }, 1305 1305 { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, }, ··· 1309 1309 }; 1310 1310 1311 1311 /* mode 4 - fits in 16KB */ 1312 - static struct musb_fifo_cfg mode_4_cfg[] = { 1312 + static const struct musb_fifo_cfg mode_4_cfg[] = { 1313 1313 { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, }, 1314 1314 { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, }, 1315 1315 { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, }, ··· 1340 1340 }; 1341 1341 1342 1342 /* mode 5 - fits in 8KB */ 1343 - static struct musb_fifo_cfg mode_5_cfg[] = { 1343 + static const struct musb_fifo_cfg mode_5_cfg[] = { 1344 1344 { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, }, 1345 1345 { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, }, 1346 1346 { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, }, ··· 1447 1447 return offset + (maxpacket << ((c_size & MUSB_FIFOSZ_DPB) ? 1 : 0)); 1448 1448 } 1449 1449 1450 - static struct musb_fifo_cfg ep0_cfg = { 1450 + static const struct musb_fifo_cfg ep0_cfg = { 1451 1451 .style = FIFO_RXTX, .maxpacket = 64, 1452 1452 }; 1453 1453
+2 -2
drivers/usb/musb/sunxi.c
··· 629 629 #define SUNXI_MUSB_RAM_BITS 11 630 630 631 631 /* Allwinner OTG supports up to 5 endpoints */ 632 - static struct musb_fifo_cfg sunxi_musb_mode_cfg_5eps[] = { 632 + static const struct musb_fifo_cfg sunxi_musb_mode_cfg_5eps[] = { 633 633 MUSB_EP_FIFO_SINGLE(1, FIFO_TX, 512), 634 634 MUSB_EP_FIFO_SINGLE(1, FIFO_RX, 512), 635 635 MUSB_EP_FIFO_SINGLE(2, FIFO_TX, 512), ··· 643 643 }; 644 644 645 645 /* H3/V3s OTG supports only 4 endpoints */ 646 - static struct musb_fifo_cfg sunxi_musb_mode_cfg_4eps[] = { 646 + static const struct musb_fifo_cfg sunxi_musb_mode_cfg_4eps[] = { 647 647 MUSB_EP_FIFO_SINGLE(1, FIFO_TX, 512), 648 648 MUSB_EP_FIFO_SINGLE(1, FIFO_RX, 512), 649 649 MUSB_EP_FIFO_SINGLE(2, FIFO_TX, 512),
+1 -1
include/linux/usb/musb.h
··· 61 61 }; 62 62 63 63 struct musb_hdrc_config { 64 - struct musb_fifo_cfg *fifo_cfg; /* board fifo configuration */ 64 + const struct musb_fifo_cfg *fifo_cfg; /* board fifo configuration */ 65 65 unsigned fifo_cfg_size; /* size of the fifo configuration */ 66 66 67 67 /* MUSB configuration-specific details */