Commit ce628966 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by David S. Miller

caif: reduce stack size with KASAN

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: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent aa73dc95
...@@ -32,6 +32,33 @@ void cfpkt_destroy(struct cfpkt *pkt); ...@@ -32,6 +32,33 @@ void cfpkt_destroy(struct cfpkt *pkt);
*/ */
int cfpkt_extr_head(struct cfpkt *pkt, void *data, u16 len); 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. * Peek header from packet.
* Reads data from packet without changing packet. * Reads data from packet without changing packet.
......
...@@ -352,15 +352,14 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt) ...@@ -352,15 +352,14 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt)
u8 cmdrsp; u8 cmdrsp;
u8 cmd; u8 cmd;
int ret = -1; int ret = -1;
u16 tmp16;
u8 len; u8 len;
u8 param[255]; u8 param[255];
u8 linkid; u8 linkid = 0;
struct cfctrl *cfctrl = container_obj(layer); struct cfctrl *cfctrl = container_obj(layer);
struct cfctrl_request_info rsp, *req; struct cfctrl_request_info rsp, *req;
cfpkt_extr_head(pkt, &cmdrsp, 1); cmdrsp = cfpkt_extr_head_u8(pkt);
cmd = cmdrsp & CFCTRL_CMD_MASK; cmd = cmdrsp & CFCTRL_CMD_MASK;
if (cmd != CFCTRL_CMD_LINK_ERR if (cmd != CFCTRL_CMD_LINK_ERR
&& CFCTRL_RSP_BIT != (CFCTRL_RSP_BIT & cmdrsp) && CFCTRL_RSP_BIT != (CFCTRL_RSP_BIT & cmdrsp)
...@@ -378,13 +377,12 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt) ...@@ -378,13 +377,12 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt)
u8 physlinkid; u8 physlinkid;
u8 prio; u8 prio;
u8 tmp; u8 tmp;
u32 tmp32;
u8 *cp; u8 *cp;
int i; int i;
struct cfctrl_link_param linkparam; struct cfctrl_link_param linkparam;
memset(&linkparam, 0, sizeof(linkparam)); memset(&linkparam, 0, sizeof(linkparam));
cfpkt_extr_head(pkt, &tmp, 1); tmp = cfpkt_extr_head_u8(pkt);
serv = tmp & CFCTRL_SRV_MASK; serv = tmp & CFCTRL_SRV_MASK;
linkparam.linktype = serv; linkparam.linktype = serv;
...@@ -392,13 +390,13 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt) ...@@ -392,13 +390,13 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt)
servtype = tmp >> 4; servtype = tmp >> 4;
linkparam.chtype = servtype; linkparam.chtype = servtype;
cfpkt_extr_head(pkt, &tmp, 1); tmp = cfpkt_extr_head_u8(pkt);
physlinkid = tmp & 0x07; physlinkid = tmp & 0x07;
prio = tmp >> 3; prio = tmp >> 3;
linkparam.priority = prio; linkparam.priority = prio;
linkparam.phyid = physlinkid; linkparam.phyid = physlinkid;
cfpkt_extr_head(pkt, &endpoint, 1); endpoint = cfpkt_extr_head_u8(pkt);
linkparam.endpoint = endpoint & 0x03; linkparam.endpoint = endpoint & 0x03;
switch (serv) { switch (serv) {
...@@ -407,45 +405,43 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt) ...@@ -407,45 +405,43 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt)
if (CFCTRL_ERR_BIT & cmdrsp) if (CFCTRL_ERR_BIT & cmdrsp)
break; break;
/* Link ID */ /* Link ID */
cfpkt_extr_head(pkt, &linkid, 1); linkid = cfpkt_extr_head_u8(pkt);
break; break;
case CFCTRL_SRV_VIDEO: case CFCTRL_SRV_VIDEO:
cfpkt_extr_head(pkt, &tmp, 1); tmp = cfpkt_extr_head_u8(pkt);
linkparam.u.video.connid = tmp; linkparam.u.video.connid = tmp;
if (CFCTRL_ERR_BIT & cmdrsp) if (CFCTRL_ERR_BIT & cmdrsp)
break; break;
/* Link ID */ /* Link ID */
cfpkt_extr_head(pkt, &linkid, 1); linkid = cfpkt_extr_head_u8(pkt);
break; break;
case CFCTRL_SRV_DATAGRAM: case CFCTRL_SRV_DATAGRAM:
cfpkt_extr_head(pkt, &tmp32, 4);
linkparam.u.datagram.connid = linkparam.u.datagram.connid =
le32_to_cpu(tmp32); cfpkt_extr_head_u32(pkt);
if (CFCTRL_ERR_BIT & cmdrsp) if (CFCTRL_ERR_BIT & cmdrsp)
break; break;
/* Link ID */ /* Link ID */
cfpkt_extr_head(pkt, &linkid, 1); linkid = cfpkt_extr_head_u8(pkt);
break; break;
case CFCTRL_SRV_RFM: case CFCTRL_SRV_RFM:
/* Construct a frame, convert /* Construct a frame, convert
* DatagramConnectionID * DatagramConnectionID
* to network format long and copy it out... * to network format long and copy it out...
*/ */
cfpkt_extr_head(pkt, &tmp32, 4);
linkparam.u.rfm.connid = linkparam.u.rfm.connid =
le32_to_cpu(tmp32); cfpkt_extr_head_u32(pkt);
cp = (u8 *) linkparam.u.rfm.volume; 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_more(pkt) && tmp != '\0';
cfpkt_extr_head(pkt, &tmp, 1)) tmp = cfpkt_extr_head_u8(pkt))
*cp++ = tmp; *cp++ = tmp;
*cp = '\0'; *cp = '\0';
if (CFCTRL_ERR_BIT & cmdrsp) if (CFCTRL_ERR_BIT & cmdrsp)
break; break;
/* Link ID */ /* Link ID */
cfpkt_extr_head(pkt, &linkid, 1); linkid = cfpkt_extr_head_u8(pkt);
break; break;
case CFCTRL_SRV_UTIL: case CFCTRL_SRV_UTIL:
...@@ -454,13 +450,11 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt) ...@@ -454,13 +450,11 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt)
* to network format long and copy it out... * to network format long and copy it out...
*/ */
/* Fifosize KB */ /* Fifosize KB */
cfpkt_extr_head(pkt, &tmp16, 2);
linkparam.u.utility.fifosize_kb = linkparam.u.utility.fifosize_kb =
le16_to_cpu(tmp16); cfpkt_extr_head_u16(pkt);
/* Fifosize bufs */ /* Fifosize bufs */
cfpkt_extr_head(pkt, &tmp16, 2);
linkparam.u.utility.fifosize_bufs = linkparam.u.utility.fifosize_bufs =
le16_to_cpu(tmp16); cfpkt_extr_head_u16(pkt);
/* name */ /* name */
cp = (u8 *) linkparam.u.utility.name; cp = (u8 *) linkparam.u.utility.name;
caif_assert(sizeof(linkparam.u.utility.name) caif_assert(sizeof(linkparam.u.utility.name)
...@@ -468,24 +462,24 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt) ...@@ -468,24 +462,24 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt)
for (i = 0; for (i = 0;
i < UTILITY_NAME_LENGTH i < UTILITY_NAME_LENGTH
&& cfpkt_more(pkt); i++) { && cfpkt_more(pkt); i++) {
cfpkt_extr_head(pkt, &tmp, 1); tmp = cfpkt_extr_head_u8(pkt);
*cp++ = tmp; *cp++ = tmp;
} }
/* Length */ /* Length */
cfpkt_extr_head(pkt, &len, 1); len = cfpkt_extr_head_u8(pkt);
linkparam.u.utility.paramlen = len; linkparam.u.utility.paramlen = len;
/* Param Data */ /* Param Data */
cp = linkparam.u.utility.params; cp = linkparam.u.utility.params;
while (cfpkt_more(pkt) && len--) { while (cfpkt_more(pkt) && len--) {
cfpkt_extr_head(pkt, &tmp, 1); tmp = cfpkt_extr_head_u8(pkt);
*cp++ = tmp; *cp++ = tmp;
} }
if (CFCTRL_ERR_BIT & cmdrsp) if (CFCTRL_ERR_BIT & cmdrsp)
break; break;
/* Link ID */ /* Link ID */
cfpkt_extr_head(pkt, &linkid, 1); linkid = cfpkt_extr_head_u8(pkt);
/* Length */ /* Length */
cfpkt_extr_head(pkt, &len, 1); len = cfpkt_extr_head_u8(pkt);
/* Param Data */ /* Param Data */
cfpkt_extr_head(pkt, &param, len); cfpkt_extr_head(pkt, &param, len);
break; break;
...@@ -522,7 +516,7 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt) ...@@ -522,7 +516,7 @@ static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt)
} }
break; break;
case CFCTRL_CMD_LINK_DESTROY: 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); cfctrl->res.linkdestroy_rsp(cfctrl->serv.layer.up, linkid);
break; break;
case CFCTRL_CMD_LINK_ERR: case CFCTRL_CMD_LINK_ERR:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment