Skip to content

Commit 383cd6d

Browse files
ColinIanKingmartinkpetersen
authored andcommitted
scsi: scsi_debug: Make read-only arrays static const
Don't populate the read-only arrays on the stack at run time, instead make them static const. Also reduces overall size. before: text data bss dec hex filename 367439 89582 5952 462973 7107d drivers/scsi/scsi_debug.o after: text data bss dec hex filename 365847 90702 5952 462501 70ea5 drivers/scsi/scsi_debug.o (gcc 14.2.0, x86-64) Signed-off-by: Colin Ian King <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Bart Van Assche <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent a2f54ff commit 383cd6d

File tree

1 file changed

+57
-34
lines changed

1 file changed

+57
-34
lines changed

drivers/scsi/scsi_debug.c

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,8 +2674,10 @@ static int resp_rsup_tmfs(struct scsi_cmnd *scp,
26742674

26752675
static int resp_err_recov_pg(unsigned char *p, int pcontrol, int target)
26762676
{ /* Read-Write Error Recovery page for mode_sense */
2677-
unsigned char err_recov_pg[] = {0x1, 0xa, 0xc0, 11, 240, 0, 0, 0,
2678-
5, 0, 0xff, 0xff};
2677+
static const unsigned char err_recov_pg[] = {
2678+
0x1, 0xa, 0xc0, 11, 240, 0, 0, 0,
2679+
5, 0, 0xff, 0xff
2680+
};
26792681

26802682
memcpy(p, err_recov_pg, sizeof(err_recov_pg));
26812683
if (1 == pcontrol)
@@ -2685,8 +2687,10 @@ static int resp_err_recov_pg(unsigned char *p, int pcontrol, int target)
26852687

26862688
static int resp_disconnect_pg(unsigned char *p, int pcontrol, int target)
26872689
{ /* Disconnect-Reconnect page for mode_sense */
2688-
unsigned char disconnect_pg[] = {0x2, 0xe, 128, 128, 0, 10, 0, 0,
2689-
0, 0, 0, 0, 0, 0, 0, 0};
2690+
static const unsigned char disconnect_pg[] = {
2691+
0x2, 0xe, 128, 128, 0, 10, 0, 0,
2692+
0, 0, 0, 0, 0, 0, 0, 0
2693+
};
26902694

26912695
memcpy(p, disconnect_pg, sizeof(disconnect_pg));
26922696
if (1 == pcontrol)
@@ -2696,9 +2700,11 @@ static int resp_disconnect_pg(unsigned char *p, int pcontrol, int target)
26962700

26972701
static int resp_format_pg(unsigned char *p, int pcontrol, int target)
26982702
{ /* Format device page for mode_sense */
2699-
unsigned char format_pg[] = {0x3, 0x16, 0, 0, 0, 0, 0, 0,
2700-
0, 0, 0, 0, 0, 0, 0, 0,
2701-
0, 0, 0, 0, 0x40, 0, 0, 0};
2703+
static const unsigned char format_pg[] = {
2704+
0x3, 0x16, 0, 0, 0, 0, 0, 0,
2705+
0, 0, 0, 0, 0, 0, 0, 0,
2706+
0, 0, 0, 0, 0x40, 0, 0, 0
2707+
};
27022708

27032709
memcpy(p, format_pg, sizeof(format_pg));
27042710
put_unaligned_be16(sdebug_sectors_per, p + 10);
@@ -2716,10 +2722,14 @@ static unsigned char caching_pg[] = {0x8, 18, 0x14, 0, 0xff, 0xff, 0, 0,
27162722

27172723
static int resp_caching_pg(unsigned char *p, int pcontrol, int target)
27182724
{ /* Caching page for mode_sense */
2719-
unsigned char ch_caching_pg[] = {/* 0x8, 18, */ 0x4, 0, 0, 0, 0, 0,
2720-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
2721-
unsigned char d_caching_pg[] = {0x8, 18, 0x14, 0, 0xff, 0xff, 0, 0,
2722-
0xff, 0xff, 0xff, 0xff, 0x80, 0x14, 0, 0, 0, 0, 0, 0};
2725+
static const unsigned char ch_caching_pg[] = {
2726+
/* 0x8, 18, */ 0x4, 0, 0, 0, 0, 0,
2727+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
2728+
};
2729+
static const unsigned char d_caching_pg[] = {
2730+
0x8, 18, 0x14, 0, 0xff, 0xff, 0, 0,
2731+
0xff, 0xff, 0xff, 0xff, 0x80, 0x14, 0, 0, 0, 0, 0, 0
2732+
};
27232733

27242734
if (SDEBUG_OPT_N_WCE & sdebug_opts)
27252735
caching_pg[2] &= ~0x4; /* set WCE=0 (default WCE=1) */
@@ -2738,8 +2748,10 @@ static int resp_ctrl_m_pg(unsigned char *p, int pcontrol, int target)
27382748
{ /* Control mode page for mode_sense */
27392749
unsigned char ch_ctrl_m_pg[] = {/* 0xa, 10, */ 0x6, 0, 0, 0, 0, 0,
27402750
0, 0, 0, 0};
2741-
unsigned char d_ctrl_m_pg[] = {0xa, 10, 2, 0, 0, 0, 0, 0,
2742-
0, 0, 0x2, 0x4b};
2751+
static const unsigned char d_ctrl_m_pg[] = {
2752+
0xa, 10, 2, 0, 0, 0, 0, 0,
2753+
0, 0, 0x2, 0x4b
2754+
};
27432755

27442756
if (sdebug_dsense)
27452757
ctrl_m_pg[2] |= 0x4;
@@ -2794,10 +2806,14 @@ static int resp_grouping_m_pg(unsigned char *p, int pcontrol, int target)
27942806

27952807
static int resp_iec_m_pg(unsigned char *p, int pcontrol, int target)
27962808
{ /* Informational Exceptions control mode page for mode_sense */
2797-
unsigned char ch_iec_m_pg[] = {/* 0x1c, 0xa, */ 0x4, 0xf, 0, 0, 0, 0,
2798-
0, 0, 0x0, 0x0};
2799-
unsigned char d_iec_m_pg[] = {0x1c, 0xa, 0x08, 0, 0, 0, 0, 0,
2800-
0, 0, 0x0, 0x0};
2809+
static const unsigned char ch_iec_m_pg[] = {
2810+
/* 0x1c, 0xa, */ 0x4, 0xf, 0, 0, 0, 0,
2811+
0, 0, 0x0, 0x0
2812+
};
2813+
static const unsigned char d_iec_m_pg[] = {
2814+
0x1c, 0xa, 0x08, 0, 0, 0, 0, 0,
2815+
0, 0, 0x0, 0x0
2816+
};
28012817

28022818
memcpy(p, iec_m_pg, sizeof(iec_m_pg));
28032819
if (1 == pcontrol)
@@ -2809,8 +2825,9 @@ static int resp_iec_m_pg(unsigned char *p, int pcontrol, int target)
28092825

28102826
static int resp_sas_sf_m_pg(unsigned char *p, int pcontrol, int target)
28112827
{ /* SAS SSP mode page - short format for mode_sense */
2812-
unsigned char sas_sf_m_pg[] = {0x19, 0x6,
2813-
0x6, 0x0, 0x7, 0xd0, 0x0, 0x0};
2828+
static const unsigned char sas_sf_m_pg[] = {
2829+
0x19, 0x6, 0x6, 0x0, 0x7, 0xd0, 0x0, 0x0
2830+
};
28142831

28152832
memcpy(p, sas_sf_m_pg, sizeof(sas_sf_m_pg));
28162833
if (1 == pcontrol)
@@ -2854,9 +2871,10 @@ static int resp_sas_pcd_m_spg(unsigned char *p, int pcontrol, int target,
28542871

28552872
static int resp_sas_sha_m_spg(unsigned char *p, int pcontrol)
28562873
{ /* SAS SSP shared protocol specific port mode subpage */
2857-
unsigned char sas_sha_m_pg[] = {0x59, 0x2, 0, 0xc, 0, 0x6, 0x10, 0,
2858-
0, 0, 0, 0, 0, 0, 0, 0,
2859-
};
2874+
static const unsigned char sas_sha_m_pg[] = {
2875+
0x59, 0x2, 0, 0xc, 0, 0x6, 0x10, 0,
2876+
0, 0, 0, 0, 0, 0, 0, 0,
2877+
};
28602878

28612879
memcpy(p, sas_sha_m_pg, sizeof(sas_sha_m_pg));
28622880
if (1 == pcontrol)
@@ -2923,8 +2941,10 @@ static int process_medium_part_m_pg(struct sdebug_dev_info *devip,
29232941
static int resp_compression_m_pg(unsigned char *p, int pcontrol, int target,
29242942
unsigned char dce)
29252943
{ /* Compression page for mode_sense (tape) */
2926-
unsigned char compression_pg[] = {0x0f, 14, 0x40, 0, 0, 0, 0, 0,
2927-
0, 0, 0, 0, 00, 00};
2944+
static const unsigned char compression_pg[] = {
2945+
0x0f, 14, 0x40, 0, 0, 0, 0, 0,
2946+
0, 0, 0, 0, 0, 0
2947+
};
29282948

29292949
memcpy(p, compression_pg, sizeof(compression_pg));
29302950
if (dce)
@@ -3282,18 +3302,20 @@ static int resp_mode_select(struct scsi_cmnd *scp,
32823302

32833303
static int resp_temp_l_pg(unsigned char *arr)
32843304
{
3285-
unsigned char temp_l_pg[] = {0x0, 0x0, 0x3, 0x2, 0x0, 38,
3286-
0x0, 0x1, 0x3, 0x2, 0x0, 65,
3287-
};
3305+
static const unsigned char temp_l_pg[] = {
3306+
0x0, 0x0, 0x3, 0x2, 0x0, 38,
3307+
0x0, 0x1, 0x3, 0x2, 0x0, 65,
3308+
};
32883309

32893310
memcpy(arr, temp_l_pg, sizeof(temp_l_pg));
32903311
return sizeof(temp_l_pg);
32913312
}
32923313

32933314
static int resp_ie_l_pg(unsigned char *arr)
32943315
{
3295-
unsigned char ie_l_pg[] = {0x0, 0x0, 0x3, 0x3, 0x0, 0x0, 38,
3296-
};
3316+
static const unsigned char ie_l_pg[] = {
3317+
0x0, 0x0, 0x3, 0x3, 0x0, 0x0, 38,
3318+
};
32973319

32983320
memcpy(arr, ie_l_pg, sizeof(ie_l_pg));
32993321
if (iec_m_pg[2] & 0x4) { /* TEST bit set */
@@ -3305,11 +3327,12 @@ static int resp_ie_l_pg(unsigned char *arr)
33053327

33063328
static int resp_env_rep_l_spg(unsigned char *arr)
33073329
{
3308-
unsigned char env_rep_l_spg[] = {0x0, 0x0, 0x23, 0x8,
3309-
0x0, 40, 72, 0xff, 45, 18, 0, 0,
3310-
0x1, 0x0, 0x23, 0x8,
3311-
0x0, 55, 72, 35, 55, 45, 0, 0,
3312-
};
3330+
static const unsigned char env_rep_l_spg[] = {
3331+
0x0, 0x0, 0x23, 0x8,
3332+
0x0, 40, 72, 0xff, 45, 18, 0, 0,
3333+
0x1, 0x0, 0x23, 0x8,
3334+
0x0, 55, 72, 35, 55, 45, 0, 0,
3335+
};
33133336

33143337
memcpy(arr, env_rep_l_spg, sizeof(env_rep_l_spg));
33153338
return sizeof(env_rep_l_spg);

0 commit comments

Comments
 (0)