staging: r8188eu: use sizeof instead of hardcoded firmware header size
authorMichael Straube <straube.linux@gmail.com>
Sun, 17 Apr 2022 17:54:38 +0000 (19:54 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Apr 2022 16:31:18 +0000 (18:31 +0200)
Use sizeof() instead of hardcoding the firmware header size and add
a compile time check to ensure struct rt_firmware_hdr has the correct
size.

Acked-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: Michael Straube <straube.linux@gmail.com>
Link: https://lore.kernel.org/r/20220417175441.13830-6-straube.linux@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/r8188eu/core/rtw_fw.c

index a80cc7f..42b3650 100644 (file)
@@ -39,6 +39,8 @@ struct rt_firmware_hdr {
        __le32  rsvd5;
 };
 
+static_assert(sizeof(struct rt_firmware_hdr) == 32);
+
 static void fw_download_enable(struct adapter *padapter, bool enable)
 {
        u8 tmp;
@@ -268,9 +270,8 @@ int rtl8188e_firmware_download(struct adapter *padapter)
                        DRIVER_PREFIX, fw_version, fw_subversion, fw_signature);
 
        if (IS_FW_HEADER_EXIST(fwhdr)) {
-               /*  Shift 32 bytes for FW header */
-               fw_data = fw_data + 32;
-               fw_size = fw_size - 32;
+               fw_data = fw_data + sizeof(struct rt_firmware_hdr);
+               fw_size = fw_size - sizeof(struct rt_firmware_hdr);
        }
 
        /*  Suggested by Filen. If 8051 is running in RAM code, driver should inform Fw to reset by itself, */