Skip to content

Commit fdb1db6

Browse files
keesmartinkpetersen
authored andcommitted
scsi: aacraid: struct {user,}sgmap{,64,raw}: Replace 1-element arrays with flexible arrays
Replace the deprecated[1] use of 1-element arrays in struct sgmap, struct sgmap64, struct sgmapraw, struct user_sgmap, and struct user_sgmap64 with modern flexible arrays. Additionally remove struct user_sgmapraw as it is unused. The resulting binary output differences from this change are limited only to stack space consumption of the smaller "srbu" variable in aac_issue_safw_bmic_identify() and aac_get_safw_ciss_luns(), as well as the smaller associated pair of memcpy()s in aac_send_safw_bmic_cmd(). Artificially growing the size of srbu back to its prior size removes all binary differences[2]. As an aside, after studying the aacraid driver code I wonder how aac_send_wellness_command() ever works. It is reporting a size 4 bytes too small for what it has constructed in memory in the DMA region: sgentry64 is size 12, whereas sgentry is size 8. Perhaps the hardware doesn't care. (Regardless, it is unchanged by this patch.) Link: KSPP#79 [1] Link: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?h=dev/v6.10-rc2/1-element&id=45e6226bcbc5e982541754eca7ac29f403e82f5e [2] Signed-off-by: Kees Cook <kees@kernel.org> Link: https://lore.kernel.org/r/20240711215739.208776-2-kees@kernel.org Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 6e5860b commit fdb1db6

5 files changed

Lines changed: 23 additions & 30 deletions

File tree

drivers/scsi/aacraid/aachba.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u3
12671267
return ret;
12681268
command = ContainerRawIo;
12691269
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));
12711271
}
12721272

12731273
BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
@@ -1302,7 +1302,7 @@ static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u
13021302
if (ret < 0)
13031303
return ret;
13041304
fibsize = sizeof(struct aac_read64) +
1305-
((le32_to_cpu(readcmd->sg.count) - 1) *
1305+
(le32_to_cpu(readcmd->sg.count) *
13061306
sizeof (struct sgentry64));
13071307
BUG_ON (fibsize > (fib->dev->max_fib_size -
13081308
sizeof(struct aac_fibhdr)));
@@ -1337,7 +1337,7 @@ static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32
13371337
if (ret < 0)
13381338
return ret;
13391339
fibsize = sizeof(struct aac_read) +
1340-
((le32_to_cpu(readcmd->sg.count) - 1) *
1340+
(le32_to_cpu(readcmd->sg.count) *
13411341
sizeof (struct sgentry));
13421342
BUG_ON (fibsize > (fib->dev->max_fib_size -
13431343
sizeof(struct aac_fibhdr)));
@@ -1401,7 +1401,7 @@ static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u
14011401
return ret;
14021402
command = ContainerRawIo;
14031403
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));
14051405
}
14061406

14071407
BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
@@ -1436,7 +1436,7 @@ static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba,
14361436
if (ret < 0)
14371437
return ret;
14381438
fibsize = sizeof(struct aac_write64) +
1439-
((le32_to_cpu(writecmd->sg.count) - 1) *
1439+
(le32_to_cpu(writecmd->sg.count) *
14401440
sizeof (struct sgentry64));
14411441
BUG_ON (fibsize > (fib->dev->max_fib_size -
14421442
sizeof(struct aac_fibhdr)));
@@ -1473,7 +1473,7 @@ static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u3
14731473
if (ret < 0)
14741474
return ret;
14751475
fibsize = sizeof(struct aac_write) +
1476-
((le32_to_cpu(writecmd->sg.count) - 1) *
1476+
(le32_to_cpu(writecmd->sg.count) *
14771477
sizeof (struct sgentry));
14781478
BUG_ON (fibsize > (fib->dev->max_fib_size -
14791479
sizeof(struct aac_fibhdr)));
@@ -1592,9 +1592,9 @@ static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
15921592
/*
15931593
* Build Scatter/Gather list
15941594
*/
1595-
fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
1595+
fibsize = sizeof(struct aac_srb) +
15961596
((le32_to_cpu(srbcmd->sg.count) & 0xff) *
1597-
sizeof (struct sgentry64));
1597+
sizeof(struct sgentry64));
15981598
BUG_ON (fibsize > (fib->dev->max_fib_size -
15991599
sizeof(struct aac_fibhdr)));
16001600

@@ -1624,7 +1624,7 @@ static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
16241624
* Build Scatter/Gather list
16251625
*/
16261626
fibsize = sizeof (struct aac_srb) +
1627-
(((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1627+
((le32_to_cpu(srbcmd->sg.count) & 0xff) *
16281628
sizeof (struct sgentry));
16291629
BUG_ON (fibsize > (fib->dev->max_fib_size -
16301630
sizeof(struct aac_fibhdr)));
@@ -1693,8 +1693,7 @@ static int aac_send_safw_bmic_cmd(struct aac_dev *dev,
16931693
fibptr->hw_fib_va->header.XferState &=
16941694
~cpu_to_le32(FastResponseCapable);
16951695

1696-
fibsize = sizeof(struct aac_srb) - sizeof(struct sgentry) +
1697-
sizeof(struct sgentry64);
1696+
fibsize = sizeof(struct aac_srb) + sizeof(struct sgentry64);
16981697

16991698
/* allocate DMA buffer for response */
17001699
addr = dma_map_single(&dev->pdev->dev, xfer_buf, xfer_len,
@@ -2267,7 +2266,7 @@ int aac_get_adapter_info(struct aac_dev* dev)
22672266
dev->a_ops.adapter_bounds = aac_bounds_32;
22682267
dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
22692268
sizeof(struct aac_fibhdr) -
2270-
sizeof(struct aac_write) + sizeof(struct sgentry)) /
2269+
sizeof(struct aac_write)) /
22712270
sizeof(struct sgentry);
22722271
if (dev->dac_support) {
22732272
dev->a_ops.adapter_read = aac_read_block64;
@@ -2278,8 +2277,7 @@ int aac_get_adapter_info(struct aac_dev* dev)
22782277
dev->scsi_host_ptr->sg_tablesize =
22792278
(dev->max_fib_size -
22802279
sizeof(struct aac_fibhdr) -
2281-
sizeof(struct aac_write64) +
2282-
sizeof(struct sgentry64)) /
2280+
sizeof(struct aac_write64)) /
22832281
sizeof(struct sgentry64);
22842282
} else {
22852283
dev->a_ops.adapter_read = aac_read_block;

drivers/scsi/aacraid/aacraid.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -507,32 +507,27 @@ struct sge_ieee1212 {
507507

508508
struct sgmap {
509509
__le32 count;
510-
struct sgentry sg[1];
510+
struct sgentry sg[];
511511
};
512512

513513
struct user_sgmap {
514514
u32 count;
515-
struct user_sgentry sg[1];
515+
struct user_sgentry sg[];
516516
};
517517

518518
struct sgmap64 {
519519
__le32 count;
520-
struct sgentry64 sg[1];
520+
struct sgentry64 sg[];
521521
};
522522

523523
struct user_sgmap64 {
524524
u32 count;
525-
struct user_sgentry64 sg[1];
525+
struct user_sgentry64 sg[];
526526
};
527527

528528
struct sgmapraw {
529529
__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[];
536531
};
537532

538533
struct creation_info

drivers/scsi/aacraid/commctrl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
523523
goto cleanup;
524524
}
525525

526-
if ((fibsize < (sizeof(struct user_aac_srb) - sizeof(struct user_sgentry))) ||
526+
if ((fibsize < sizeof(struct user_aac_srb)) ||
527527
(fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))) {
528528
rcode = -EINVAL;
529529
goto cleanup;
@@ -561,7 +561,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
561561
rcode = -EINVAL;
562562
goto cleanup;
563563
}
564-
actual_fibsize = sizeof(struct aac_srb) - sizeof(struct sgentry) +
564+
actual_fibsize = sizeof(struct aac_srb) +
565565
((user_srbcmd->sg.count & 0xff) * sizeof(struct sgentry));
566566
actual_fibsize64 = actual_fibsize + (user_srbcmd->sg.count & 0xff) *
567567
(sizeof(struct sgentry64) - sizeof(struct sgentry));

drivers/scsi/aacraid/comminit.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,7 @@ struct aac_dev *aac_init_adapter(struct aac_dev *dev)
522522
spin_lock_init(&dev->iq_lock);
523523
dev->max_fib_size = sizeof(struct hw_fib);
524524
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))
527526
/ sizeof(struct sgentry);
528527
dev->comm_interface = AAC_COMM_PRODUCER;
529528
dev->raw_io_interface = dev->raw_io_64 = 0;

drivers/scsi/aacraid/commsup.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,8 +2327,9 @@ static int aac_send_wellness_command(struct aac_dev *dev, char *wellness_str,
23272327
sg64->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
23282328
sg64->sg[0].count = cpu_to_le32(datasize);
23292329

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);
23322333

23332334
dma_free_coherent(&dev->pdev->dev, datasize, dma_buf, addr);
23342335

0 commit comments

Comments
 (0)