2020-05-04 17:18:44

by Oscar Carter

[permalink] [raw]
Subject: [PATCH] staging: vt6656: Use const for read only data

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 <[email protected]>
---
drivers/staging/vt6656/baseband.c | 14 +++++++++-----
drivers/staging/vt6656/usbpipe.c | 2 +-
drivers/staging/vt6656/usbpipe.h | 2 +-
3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/vt6656/baseband.c b/drivers/staging/vt6656/baseband.c
index 1d75acaec8f3..41ae779ec61f 100644
--- a/drivers/staging/vt6656/baseband.c
+++ b/drivers/staging/vt6656/baseband.c
@@ -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;

diff --git a/drivers/staging/vt6656/usbpipe.c b/drivers/staging/vt6656/usbpipe.c
index 91b62c3dff7b..fb5e1b0dce6b 100644
--- a/drivers/staging/vt6656/usbpipe.c
+++ b/drivers/staging/vt6656/usbpipe.c
@@ -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;

diff --git a/drivers/staging/vt6656/usbpipe.h b/drivers/staging/vt6656/usbpipe.h
index 35697b58d748..1f0b2566c288 100644
--- a/drivers/staging/vt6656/usbpipe.h
+++ b/drivers/staging/vt6656/usbpipe.h
@@ -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);
--
2.20.1