staging: vt6656: Use const for read only data
authorOscar Carter <oscar.carter@gmx.com>
Mon, 4 May 2020 17:14:14 +0000 (19:14 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 5 May 2020 10:33:00 +0000 (12:33 +0200)
Use const for the arrays that are used as "read only". Also, modify the
prototype of vnt_control_out_blocks() function to use a pointer to a
const type.

The vnt_vt3184_al2230 array can't be converted to const as it's modified
later.

Then in the vnt_vt3184_init() function use two types of pointers (to
const type and to no const type) to avoid the compiler warning:

assignment discards 'const' qualifiers from pointer target type

This way decrease the .data section and increase the .rodata section
limiting the surface attack.

Before this change:
-------------------

drivers/staging/vt6656/baseband.o  :
section              size   addr
.text                1278      0
.data                 576      0
.bss                    0      0
.rodata               319      0
.comment               45      0
.note.GNU-stack         0      0
.note.gnu.property     32      0
Total                2250

After this change:
------------------

drivers/staging/vt6656/baseband.o  :
section              size   addr
.text                1278      0
.data                 256      0
.bss                    0      0
.rodata               640      0
.comment               45      0
.note.GNU-stack         0      0
.note.gnu.property     32      0
Total                2251

Signed-off-by: Oscar Carter <oscar.carter@gmx.com>
Link: https://lore.kernel.org/r/20200504171414.11307-1-oscar.carter@gmx.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/vt6656/baseband.c
drivers/staging/vt6656/usbpipe.c
drivers/staging/vt6656/usbpipe.h

index 1d75acaec8f3fd158589fd6e8e80f62f14974646..41ae779ec61f2c081d54bd24374e36a91cd622bf 100644 (file)
@@ -31,7 +31,7 @@
 #include "rf.h"
 #include "usbpipe.h"
 
-static u8 vnt_vt3184_agc[] = {
+static const u8 vnt_vt3184_agc[] = {
        0x00, 0x00, 0x02, 0x02, 0x04, 0x04, 0x06, 0x06,
        0x08, 0x08, 0x0a, 0x0a, 0x0c, 0x0c, 0x0e, 0x0e, /* 0x0f */
        0x10, 0x10, 0x12, 0x12, 0x14, 0x14, 0x16, 0x16,
@@ -78,7 +78,7 @@ static u8 vnt_vt3184_al2230[] = {
 };
 
 /* {{RobertYu:20060515, new BB setting for VT3226D0 */
-static u8 vnt_vt3184_vt3226d0[] = {
+static const u8 vnt_vt3184_vt3226d0[] = {
        0x31, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
        0x70, 0x45, 0x2a, 0x76, 0x00, 0x00, 0x80, 0x00, /* 0x0f */
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -243,7 +243,8 @@ int vnt_vt3184_init(struct vnt_private *priv)
 {
        int ret;
        u16 length;
-       u8 *addr;
+       u8 *addr = NULL;
+       const u8 *c_addr;
        u8 data;
 
        ret = vnt_control_in(priv, MESSAGE_TYPE_READ, 0, MESSAGE_REQUEST_EEPROM,
@@ -275,7 +276,7 @@ int vnt_vt3184_init(struct vnt_private *priv)
                   (priv->rf_type == RF_VT3342A0)) {
                priv->bb_rx_conf = vnt_vt3184_vt3226d0[10];
                length = sizeof(vnt_vt3184_vt3226d0);
-               addr = vnt_vt3184_vt3226d0;
+               c_addr = vnt_vt3184_vt3226d0;
 
                priv->bb_vga[0] = 0x20;
                priv->bb_vga[1] = 0x10;
@@ -291,8 +292,11 @@ int vnt_vt3184_init(struct vnt_private *priv)
                goto end;
        }
 
+       if (addr)
+               c_addr = addr;
+
        ret = vnt_control_out_blocks(priv, VNT_REG_BLOCK_SIZE,
-                                    MESSAGE_REQUEST_BBREG, length, addr);
+                                    MESSAGE_REQUEST_BBREG, length, c_addr);
        if (ret)
                goto end;
 
index 5603f3cbb33c749944db09da0ebddcdb4ec7bfd6..06dedf291db2000a8de80f88342eb60ef728fa33 100644 (file)
@@ -77,7 +77,7 @@ int vnt_control_out_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 data)
 }
 
 int vnt_control_out_blocks(struct vnt_private *priv,
-                          u16 block, u8 reg, u16 length, u8 *data)
+                          u16 block, u8 reg, u16 length, const u8 *data)
 {
        int ret = 0, i;
 
index 35697b58d748069c1a8a311b4136b712b341b878..1f0b2566c288ef9f48c6ec080897b13aee3d1256 100644 (file)
@@ -52,7 +52,7 @@ int vnt_control_out_u8(struct vnt_private *priv, u8 reg, u8 ref_off, u8 data);
 int vnt_control_in_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 *data);
 
 int vnt_control_out_blocks(struct vnt_private *priv,
-                          u16 block, u8 reg, u16 len, u8 *data);
+                          u16 block, u8 reg, u16 len, const u8 *data);
 
 int vnt_start_interrupt_urb(struct vnt_private *priv);
 int vnt_submit_rx_urb(struct vnt_private *priv, struct vnt_rcb *rcb);