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

Configure Feed

Select the types of activity you want to include in your feed.

scsi: lpfc: Use struct_group to isolate cast to larger object

When building under -Warray-bounds, a warning is generated when casting a
u32 into MAILBOX_t (which is larger). This warning is conservative, but
it's not an unreasonable change to make to improve future robustness. Use a
tagged struct_group that can refer to either the specific fields or the
first u32 separately, silencing this warning:

drivers/scsi/lpfc/lpfc_sli.c: In function 'lpfc_reset_barrier':
drivers/scsi/lpfc/lpfc_sli.c:4787:29: error: array subscript 'MAILBOX_t[0]' is partly outside array bounds of 'volatile uint32_t[1]' {aka 'volatile unsigned int[1]'} [-Werror=array-bounds]
4787 | ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
| ^~
drivers/scsi/lpfc/lpfc_sli.c:4752:27: note: while referencing 'mbox'
4752 | volatile uint32_t mbox;
| ^~~~

There is no change to the resulting executable instruction code.

Link: https://lore.kernel.org/r/20211203223351.107323-1-keescook@chromium.org
Reviewed-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Kees Cook and committed by
Martin K. Petersen
c167dd0b 532adda9

+32 -27
+17 -10
drivers/scsi/lpfc/lpfc_hw.h
··· 3675 3675 }; 3676 3676 3677 3677 typedef struct { 3678 + struct_group_tagged(MAILBOX_word0, bits, 3679 + union { 3680 + struct { 3678 3681 #ifdef __BIG_ENDIAN_BITFIELD 3679 - uint16_t mbxStatus; 3680 - uint8_t mbxCommand; 3681 - uint8_t mbxReserved:6; 3682 - uint8_t mbxHc:1; 3683 - uint8_t mbxOwner:1; /* Low order bit first word */ 3682 + uint16_t mbxStatus; 3683 + uint8_t mbxCommand; 3684 + uint8_t mbxReserved:6; 3685 + uint8_t mbxHc:1; 3686 + uint8_t mbxOwner:1; /* Low order bit first word */ 3684 3687 #else /* __LITTLE_ENDIAN_BITFIELD */ 3685 - uint8_t mbxOwner:1; /* Low order bit first word */ 3686 - uint8_t mbxHc:1; 3687 - uint8_t mbxReserved:6; 3688 - uint8_t mbxCommand; 3689 - uint16_t mbxStatus; 3688 + uint8_t mbxOwner:1; /* Low order bit first word */ 3689 + uint8_t mbxHc:1; 3690 + uint8_t mbxReserved:6; 3691 + uint8_t mbxCommand; 3692 + uint16_t mbxStatus; 3690 3693 #endif 3694 + }; 3695 + u32 word0; 3696 + }; 3697 + ); 3691 3698 3692 3699 MAILVARIANTS un; 3693 3700 union sli_var us;
+15 -17
drivers/scsi/lpfc/lpfc_sli.c
··· 4749 4749 { 4750 4750 uint32_t __iomem *resp_buf; 4751 4751 uint32_t __iomem *mbox_buf; 4752 - volatile uint32_t mbox; 4752 + volatile struct MAILBOX_word0 mbox; 4753 4753 uint32_t hc_copy, ha_copy, resp_data; 4754 4754 int i; 4755 4755 uint8_t hdrtype; ··· 4783 4783 phba->pport->stopped = 1; 4784 4784 } 4785 4785 4786 - mbox = 0; 4787 - ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD; 4788 - ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP; 4786 + mbox.word0 = 0; 4787 + mbox.mbxCommand = MBX_KILL_BOARD; 4788 + mbox.mbxOwner = OWN_CHIP; 4789 4789 4790 4790 writel(BARRIER_TEST_PATTERN, (resp_buf + 1)); 4791 4791 mbox_buf = phba->MBslimaddr; 4792 - writel(mbox, mbox_buf); 4792 + writel(mbox.word0, mbox_buf); 4793 4793 4794 4794 for (i = 0; i < 50; i++) { 4795 4795 if (lpfc_readl((resp_buf + 1), &resp_data)) ··· 4810 4810 goto clear_errat; 4811 4811 } 4812 4812 4813 - ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST; 4813 + mbox.mbxOwner = OWN_HOST; 4814 4814 resp_data = 0; 4815 4815 for (i = 0; i < 500; i++) { 4816 4816 if (lpfc_readl(resp_buf, &resp_data)) 4817 4817 return; 4818 - if (resp_data != mbox) 4818 + if (resp_data != mbox.word0) 4819 4819 mdelay(1); 4820 4820 else 4821 4821 break; ··· 5085 5085 static int 5086 5086 lpfc_sli_brdrestart_s3(struct lpfc_hba *phba) 5087 5087 { 5088 - MAILBOX_t *mb; 5088 + volatile struct MAILBOX_word0 mb; 5089 5089 struct lpfc_sli *psli; 5090 - volatile uint32_t word0; 5091 5090 void __iomem *to_slim; 5092 5091 uint32_t hba_aer_enabled; 5093 5092 ··· 5103 5104 (phba->pport) ? phba->pport->port_state : 0, 5104 5105 psli->sli_flag); 5105 5106 5106 - word0 = 0; 5107 - mb = (MAILBOX_t *) &word0; 5108 - mb->mbxCommand = MBX_RESTART; 5109 - mb->mbxHc = 1; 5107 + mb.word0 = 0; 5108 + mb.mbxCommand = MBX_RESTART; 5109 + mb.mbxHc = 1; 5110 5110 5111 5111 lpfc_reset_barrier(phba); 5112 5112 5113 5113 to_slim = phba->MBslimaddr; 5114 - writel(*(uint32_t *) mb, to_slim); 5114 + writel(mb.word0, to_slim); 5115 5115 readl(to_slim); /* flush */ 5116 5116 5117 5117 /* Only skip post after fc_ffinit is completed */ 5118 5118 if (phba->pport && phba->pport->port_state) 5119 - word0 = 1; /* This is really setting up word1 */ 5119 + mb.word0 = 1; /* This is really setting up word1 */ 5120 5120 else 5121 - word0 = 0; /* This is really setting up word1 */ 5121 + mb.word0 = 0; /* This is really setting up word1 */ 5122 5122 to_slim = phba->MBslimaddr + sizeof (uint32_t); 5123 - writel(*(uint32_t *) mb, to_slim); 5123 + writel(mb.word0, to_slim); 5124 5124 readl(to_slim); /* flush */ 5125 5125 5126 5126 lpfc_sli_brdreset(phba);