Skip to content

Commit 7a4cf27

Browse files
arndbHans Verkuil
authored andcommitted
media: dvb-frontends: avoid stack overflow warnings with clang
A previous patch worked around a KASAN issue in stv0367, now a similar problem showed up with clang: drivers/media/dvb-frontends/stv0367.c:1222:12: error: stack frame size (3624) exceeds limit (2048) in 'stv0367ter_set_frontend' [-Werror,-Wframe-larger-than] 1214 | static int stv0367ter_set_frontend(struct dvb_frontend *fe) Rework the stv0367_writereg() function to be simpler and mark both register access functions as noinline_for_stack so the temporary i2c_msg structures do not get duplicated on the stack when KASAN_STACK is enabled. Fixes: 3cd890d ("media: dvb-frontends: fix i2c access helpers for KASAN") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Reviewed-by: Justin Stitt <justinstitt@google.com> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
1 parent 0a0b79e commit 7a4cf27

File tree

1 file changed

+8
-26
lines changed

1 file changed

+8
-26
lines changed

drivers/media/dvb-frontends/stv0367.c

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -118,50 +118,32 @@ static const s32 stv0367cab_RF_LookUp2[RF_LOOKUP_TABLE2_SIZE][RF_LOOKUP_TABLE2_S
118118
}
119119
};
120120

121-
static
122-
int stv0367_writeregs(struct stv0367_state *state, u16 reg, u8 *data, int len)
121+
static noinline_for_stack
122+
int stv0367_writereg(struct stv0367_state *state, u16 reg, u8 data)
123123
{
124-
u8 buf[MAX_XFER_SIZE];
124+
u8 buf[3] = { MSB(reg), LSB(reg), data };
125125
struct i2c_msg msg = {
126126
.addr = state->config->demod_address,
127127
.flags = 0,
128128
.buf = buf,
129-
.len = len + 2
129+
.len = 3,
130130
};
131131
int ret;
132132

133-
if (2 + len > sizeof(buf)) {
134-
printk(KERN_WARNING
135-
"%s: i2c wr reg=%04x: len=%d is too big!\n",
136-
KBUILD_MODNAME, reg, len);
137-
return -EINVAL;
138-
}
139-
140-
141-
buf[0] = MSB(reg);
142-
buf[1] = LSB(reg);
143-
memcpy(buf + 2, data, len);
144-
145133
if (i2cdebug)
146134
printk(KERN_DEBUG "%s: [%02x] %02x: %02x\n", __func__,
147-
state->config->demod_address, reg, buf[2]);
135+
state->config->demod_address, reg, data);
148136

149137
ret = i2c_transfer(state->i2c, &msg, 1);
150138
if (ret != 1)
151139
printk(KERN_ERR "%s: i2c write error! ([%02x] %02x: %02x)\n",
152-
__func__, state->config->demod_address, reg, buf[2]);
140+
__func__, state->config->demod_address, reg, data);
153141

154142
return (ret != 1) ? -EREMOTEIO : 0;
155143
}
156144

157-
static int stv0367_writereg(struct stv0367_state *state, u16 reg, u8 data)
158-
{
159-
u8 tmp = data; /* see gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */
160-
161-
return stv0367_writeregs(state, reg, &tmp, 1);
162-
}
163-
164-
static u8 stv0367_readreg(struct stv0367_state *state, u16 reg)
145+
static noinline_for_stack
146+
u8 stv0367_readreg(struct stv0367_state *state, u16 reg)
165147
{
166148
u8 b0[] = { 0, 0 };
167149
u8 b1[] = { 0 };

0 commit comments

Comments
 (0)