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

Merge patch series "scsi: aacraid: struct sgmap: Replace 1-element arrays with flexible arrays"

Kees Cook <kees@kernel.org> says:

This replaces some of the last remaining uses in the kernel of
1-element "fake" flexible arrays with modern C99 flexible arrays. Some
refactoring is done to ease this, and binary differences are
identified. For the on stack size changes in patch 2, the "yes, that
is the source of the binary differences" debugging patch can be found
here[1].

[1] https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?h=dev/v6.10-rc2/1-element&id=45e6226bcbc5e982541754eca7ac29f403e82f5e

Link: https://lore.kernel.org/r/20240711212732.work.162-kees@kernel.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

+24 -31
+12 -14
drivers/scsi/aacraid/aachba.c
··· 1267 1267 return ret; 1268 1268 command = ContainerRawIo; 1269 1269 fibsize = sizeof(struct aac_raw_io) + 1270 - ((le32_to_cpu(readcmd->sg.count)-1) * sizeof(struct sgentryraw)); 1270 + (le32_to_cpu(readcmd->sg.count) * sizeof(struct sgentryraw)); 1271 1271 } 1272 1272 1273 1273 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr))); ··· 1302 1302 if (ret < 0) 1303 1303 return ret; 1304 1304 fibsize = sizeof(struct aac_read64) + 1305 - ((le32_to_cpu(readcmd->sg.count) - 1) * 1305 + (le32_to_cpu(readcmd->sg.count) * 1306 1306 sizeof (struct sgentry64)); 1307 1307 BUG_ON (fibsize > (fib->dev->max_fib_size - 1308 1308 sizeof(struct aac_fibhdr))); ··· 1337 1337 if (ret < 0) 1338 1338 return ret; 1339 1339 fibsize = sizeof(struct aac_read) + 1340 - ((le32_to_cpu(readcmd->sg.count) - 1) * 1340 + (le32_to_cpu(readcmd->sg.count) * 1341 1341 sizeof (struct sgentry)); 1342 1342 BUG_ON (fibsize > (fib->dev->max_fib_size - 1343 1343 sizeof(struct aac_fibhdr))); ··· 1401 1401 return ret; 1402 1402 command = ContainerRawIo; 1403 1403 fibsize = sizeof(struct aac_raw_io) + 1404 - ((le32_to_cpu(writecmd->sg.count)-1) * sizeof (struct sgentryraw)); 1404 + (le32_to_cpu(writecmd->sg.count) * sizeof(struct sgentryraw)); 1405 1405 } 1406 1406 1407 1407 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr))); ··· 1436 1436 if (ret < 0) 1437 1437 return ret; 1438 1438 fibsize = sizeof(struct aac_write64) + 1439 - ((le32_to_cpu(writecmd->sg.count) - 1) * 1439 + (le32_to_cpu(writecmd->sg.count) * 1440 1440 sizeof (struct sgentry64)); 1441 1441 BUG_ON (fibsize > (fib->dev->max_fib_size - 1442 1442 sizeof(struct aac_fibhdr))); ··· 1473 1473 if (ret < 0) 1474 1474 return ret; 1475 1475 fibsize = sizeof(struct aac_write) + 1476 - ((le32_to_cpu(writecmd->sg.count) - 1) * 1476 + (le32_to_cpu(writecmd->sg.count) * 1477 1477 sizeof (struct sgentry)); 1478 1478 BUG_ON (fibsize > (fib->dev->max_fib_size - 1479 1479 sizeof(struct aac_fibhdr))); ··· 1592 1592 /* 1593 1593 * Build Scatter/Gather list 1594 1594 */ 1595 - fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) + 1595 + fibsize = sizeof(struct aac_srb) + 1596 1596 ((le32_to_cpu(srbcmd->sg.count) & 0xff) * 1597 - sizeof (struct sgentry64)); 1597 + sizeof(struct sgentry64)); 1598 1598 BUG_ON (fibsize > (fib->dev->max_fib_size - 1599 1599 sizeof(struct aac_fibhdr))); 1600 1600 ··· 1624 1624 * Build Scatter/Gather list 1625 1625 */ 1626 1626 fibsize = sizeof (struct aac_srb) + 1627 - (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) * 1627 + ((le32_to_cpu(srbcmd->sg.count) & 0xff) * 1628 1628 sizeof (struct sgentry)); 1629 1629 BUG_ON (fibsize > (fib->dev->max_fib_size - 1630 1630 sizeof(struct aac_fibhdr))); ··· 1693 1693 fibptr->hw_fib_va->header.XferState &= 1694 1694 ~cpu_to_le32(FastResponseCapable); 1695 1695 1696 - fibsize = sizeof(struct aac_srb) - sizeof(struct sgentry) + 1697 - sizeof(struct sgentry64); 1696 + fibsize = sizeof(struct aac_srb) + sizeof(struct sgentry64); 1698 1697 1699 1698 /* allocate DMA buffer for response */ 1700 1699 addr = dma_map_single(&dev->pdev->dev, xfer_buf, xfer_len, ··· 2266 2267 dev->a_ops.adapter_bounds = aac_bounds_32; 2267 2268 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size - 2268 2269 sizeof(struct aac_fibhdr) - 2269 - sizeof(struct aac_write) + sizeof(struct sgentry)) / 2270 + sizeof(struct aac_write)) / 2270 2271 sizeof(struct sgentry); 2271 2272 if (dev->dac_support) { 2272 2273 dev->a_ops.adapter_read = aac_read_block64; ··· 2277 2278 dev->scsi_host_ptr->sg_tablesize = 2278 2279 (dev->max_fib_size - 2279 2280 sizeof(struct aac_fibhdr) - 2280 - sizeof(struct aac_write64) + 2281 - sizeof(struct sgentry64)) / 2281 + sizeof(struct aac_write64)) / 2282 2282 sizeof(struct sgentry64); 2283 2283 } else { 2284 2284 dev->a_ops.adapter_read = aac_read_block;
+6 -11
drivers/scsi/aacraid/aacraid.h
··· 507 507 508 508 struct sgmap { 509 509 __le32 count; 510 - struct sgentry sg[1]; 510 + struct sgentry sg[]; 511 511 }; 512 512 513 513 struct user_sgmap { 514 514 u32 count; 515 - struct user_sgentry sg[1]; 515 + struct user_sgentry sg[]; 516 516 }; 517 517 518 518 struct sgmap64 { 519 519 __le32 count; 520 - struct sgentry64 sg[1]; 520 + struct sgentry64 sg[]; 521 521 }; 522 522 523 523 struct user_sgmap64 { 524 524 u32 count; 525 - struct user_sgentry64 sg[1]; 525 + struct user_sgentry64 sg[]; 526 526 }; 527 527 528 528 struct sgmapraw { 529 529 __le32 count; 530 - struct sgentryraw sg[1]; 531 - }; 532 - 533 - struct user_sgmapraw { 534 - u32 count; 535 - struct user_sgentryraw sg[1]; 530 + struct sgentryraw sg[]; 536 531 }; 537 532 538 533 struct creation_info ··· 2024 2029 }; 2025 2030 2026 2031 struct aac_srb_unit { 2027 - struct aac_srb srb; 2028 2032 struct aac_srb_reply srb_reply; 2033 + struct aac_srb srb; 2029 2034 }; 2030 2035 2031 2036 /*
+2 -2
drivers/scsi/aacraid/commctrl.c
··· 523 523 goto cleanup; 524 524 } 525 525 526 - if ((fibsize < (sizeof(struct user_aac_srb) - sizeof(struct user_sgentry))) || 526 + if ((fibsize < sizeof(struct user_aac_srb)) || 527 527 (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))) { 528 528 rcode = -EINVAL; 529 529 goto cleanup; ··· 561 561 rcode = -EINVAL; 562 562 goto cleanup; 563 563 } 564 - actual_fibsize = sizeof(struct aac_srb) - sizeof(struct sgentry) + 564 + actual_fibsize = sizeof(struct aac_srb) + 565 565 ((user_srbcmd->sg.count & 0xff) * sizeof(struct sgentry)); 566 566 actual_fibsize64 = actual_fibsize + (user_srbcmd->sg.count & 0xff) * 567 567 (sizeof(struct sgentry64) - sizeof(struct sgentry));
+1 -2
drivers/scsi/aacraid/comminit.c
··· 522 522 spin_lock_init(&dev->iq_lock); 523 523 dev->max_fib_size = sizeof(struct hw_fib); 524 524 dev->sg_tablesize = host->sg_tablesize = (dev->max_fib_size 525 - - sizeof(struct aac_fibhdr) 526 - - sizeof(struct aac_write) + sizeof(struct sgentry)) 525 + - sizeof(struct aac_fibhdr) - sizeof(struct aac_write)) 527 526 / sizeof(struct sgentry); 528 527 dev->comm_interface = AAC_COMM_PRODUCER; 529 528 dev->raw_io_interface = dev->raw_io_64 = 0;
+3 -2
drivers/scsi/aacraid/commsup.c
··· 2327 2327 sg64->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff)); 2328 2328 sg64->sg[0].count = cpu_to_le32(datasize); 2329 2329 2330 - ret = aac_fib_send(ScsiPortCommand64, fibptr, sizeof(struct aac_srb), 2331 - FsaNormal, 1, 1, NULL, NULL); 2330 + ret = aac_fib_send(ScsiPortCommand64, fibptr, 2331 + sizeof(struct aac_srb) + sizeof(struct sgentry), 2332 + FsaNormal, 1, 1, NULL, NULL); 2332 2333 2333 2334 dma_free_coherent(&dev->pdev->dev, datasize, dma_buf, addr); 2334 2335