Skip to content

Commit

Permalink
caif: reduce stack size with KASAN
Browse files Browse the repository at this point in the history
When CONFIG_KASAN is set, we can use relatively large amounts of kernel
stack space:

net/caif/cfctrl.c:555:1: warning: the frame size of 1600 bytes is larger than 1280 bytes [-Wframe-larger-than=]

This adds convenience wrappers around cfpkt_extr_head(), which is responsible
for most of the stack growth. With those wrapper functions, gcc apparently
starts reusing the stack slots for each instance, thus avoiding the
problem.

Signed-off-by: Arnd Bergmann <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
arndb authored and davem330 committed Jan 19, 2018
1 parent aa73dc9 commit ce62896
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 28 deletions.
27 changes: 27 additions & 0 deletions include/net/caif/cfpkt.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,33 @@ void cfpkt_destroy(struct cfpkt *pkt);
*/
int cfpkt_extr_head(struct cfpkt *pkt, void *data, u16 len);

static inline u8 cfpkt_extr_head_u8(struct cfpkt *pkt)
{
u8 tmp;

cfpkt_extr_head(pkt, &tmp, 1);

return tmp;
}

static inline u16 cfpkt_extr_head_u16(struct cfpkt *pkt)
{
__le16 tmp;

cfpkt_extr_head(pkt, &tmp, 2);

return le16_to_cpu(tmp);
}

static inline u32 cfpkt_extr_head_u32(struct cfpkt *pkt)
{
__le32 tmp;

cfpkt_extr_head(pkt, &tmp, 4);

return le32_to_cpu(tmp);
}

/*
* Peek header from packet.
* Reads data from packet without changing packet.
Expand Down
50 changes: 22 additions & 28 deletions net/caif/cfctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,14 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt)
u8 cmdrsp;
u8 cmd;
int ret = -1;
u16 tmp16;
u8 len;
u8 param[255];
u8 linkid;
u8 linkid = 0;
struct cfctrl *cfctrl = container_obj(layer);
struct cfctrl_request_info rsp, *req;


cfpkt_extr_head(pkt, &cmdrsp, 1);
cmdrsp = cfpkt_extr_head_u8(pkt);
cmd = cmdrsp & CFCTRL_CMD_MASK;
if (cmd != CFCTRL_CMD_LINK_ERR
&& CFCTRL_RSP_BIT != (CFCTRL_RSP_BIT & cmdrsp)
Expand All @@ -378,27 +377,26 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt)
u8 physlinkid;
u8 prio;
u8 tmp;
u32 tmp32;
u8 *cp;
int i;
struct cfctrl_link_param linkparam;
memset(&linkparam, 0, sizeof(linkparam));

cfpkt_extr_head(pkt, &tmp, 1);
tmp = cfpkt_extr_head_u8(pkt);

serv = tmp & CFCTRL_SRV_MASK;
linkparam.linktype = serv;

servtype = tmp >> 4;
linkparam.chtype = servtype;

cfpkt_extr_head(pkt, &tmp, 1);
tmp = cfpkt_extr_head_u8(pkt);
physlinkid = tmp & 0x07;
prio = tmp >> 3;

linkparam.priority = prio;
linkparam.phyid = physlinkid;
cfpkt_extr_head(pkt, &endpoint, 1);
endpoint = cfpkt_extr_head_u8(pkt);
linkparam.endpoint = endpoint & 0x03;

switch (serv) {
Expand All @@ -407,45 +405,43 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt)
if (CFCTRL_ERR_BIT & cmdrsp)
break;
/* Link ID */
cfpkt_extr_head(pkt, &linkid, 1);
linkid = cfpkt_extr_head_u8(pkt);
break;
case CFCTRL_SRV_VIDEO:
cfpkt_extr_head(pkt, &tmp, 1);
tmp = cfpkt_extr_head_u8(pkt);
linkparam.u.video.connid = tmp;
if (CFCTRL_ERR_BIT & cmdrsp)
break;
/* Link ID */
cfpkt_extr_head(pkt, &linkid, 1);
linkid = cfpkt_extr_head_u8(pkt);
break;

case CFCTRL_SRV_DATAGRAM:
cfpkt_extr_head(pkt, &tmp32, 4);
linkparam.u.datagram.connid =
le32_to_cpu(tmp32);
cfpkt_extr_head_u32(pkt);
if (CFCTRL_ERR_BIT & cmdrsp)
break;
/* Link ID */
cfpkt_extr_head(pkt, &linkid, 1);
linkid = cfpkt_extr_head_u8(pkt);
break;
case CFCTRL_SRV_RFM:
/* Construct a frame, convert
* DatagramConnectionID
* to network format long and copy it out...
*/
cfpkt_extr_head(pkt, &tmp32, 4);
linkparam.u.rfm.connid =
le32_to_cpu(tmp32);
cfpkt_extr_head_u32(pkt);
cp = (u8 *) linkparam.u.rfm.volume;
for (cfpkt_extr_head(pkt, &tmp, 1);
for (tmp = cfpkt_extr_head_u8(pkt);
cfpkt_more(pkt) && tmp != '\0';
cfpkt_extr_head(pkt, &tmp, 1))
tmp = cfpkt_extr_head_u8(pkt))
*cp++ = tmp;
*cp = '\0';

if (CFCTRL_ERR_BIT & cmdrsp)
break;
/* Link ID */
cfpkt_extr_head(pkt, &linkid, 1);
linkid = cfpkt_extr_head_u8(pkt);

break;
case CFCTRL_SRV_UTIL:
Expand All @@ -454,38 +450,36 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt)
* to network format long and copy it out...
*/
/* Fifosize KB */
cfpkt_extr_head(pkt, &tmp16, 2);
linkparam.u.utility.fifosize_kb =
le16_to_cpu(tmp16);
cfpkt_extr_head_u16(pkt);
/* Fifosize bufs */
cfpkt_extr_head(pkt, &tmp16, 2);
linkparam.u.utility.fifosize_bufs =
le16_to_cpu(tmp16);
cfpkt_extr_head_u16(pkt);
/* name */
cp = (u8 *) linkparam.u.utility.name;
caif_assert(sizeof(linkparam.u.utility.name)
>= UTILITY_NAME_LENGTH);
for (i = 0;
i < UTILITY_NAME_LENGTH
&& cfpkt_more(pkt); i++) {
cfpkt_extr_head(pkt, &tmp, 1);
tmp = cfpkt_extr_head_u8(pkt);
*cp++ = tmp;
}
/* Length */
cfpkt_extr_head(pkt, &len, 1);
len = cfpkt_extr_head_u8(pkt);
linkparam.u.utility.paramlen = len;
/* Param Data */
cp = linkparam.u.utility.params;
while (cfpkt_more(pkt) && len--) {
cfpkt_extr_head(pkt, &tmp, 1);
tmp = cfpkt_extr_head_u8(pkt);
*cp++ = tmp;
}
if (CFCTRL_ERR_BIT & cmdrsp)
break;
/* Link ID */
cfpkt_extr_head(pkt, &linkid, 1);
linkid = cfpkt_extr_head_u8(pkt);
/* Length */
cfpkt_extr_head(pkt, &len, 1);
len = cfpkt_extr_head_u8(pkt);
/* Param Data */
cfpkt_extr_head(pkt, &param, len);
break;
Expand Down Expand Up @@ -522,7 +516,7 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt)
}
break;
case CFCTRL_CMD_LINK_DESTROY:
cfpkt_extr_head(pkt, &linkid, 1);
linkid = cfpkt_extr_head_u8(pkt);
cfctrl->res.linkdestroy_rsp(cfctrl->serv.layer.up, linkid);
break;
case CFCTRL_CMD_LINK_ERR:
Expand Down

0 comments on commit ce62896

Please sign in to comment.