Skip to content

Commit 908061f

Browse files
nehebandersson
authored andcommitted
soc: qcom: wcnss: simplify allocation of req
Get rid of automatic kfree and move allocation down to where it's used. Use kzalloc_flex as we're dealing with a flexible array member. Use struct_size to avoid some pointer math. Add __counted_by for extra runtime analysis. Move the counting variable assignment to right after allocation as required by __counted_by. Signed-off-by: Rosen Penev <rosenp@gmail.com> Link: https://lore.kernel.org/r/20260327025534.7864-1-rosenp@gmail.com Signed-off-by: Bjorn Andersson <andersson@kernel.org>
1 parent 79c9ede commit 908061f

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

drivers/soc/qcom/wcnss_ctrl.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct wcnss_download_nv_req {
9494
u16 seq;
9595
u16 last;
9696
u32 frag_size;
97-
u8 fragment[];
97+
u8 fragment[] __counted_by(frag_size);
9898
} __packed;
9999

100100
/**
@@ -201,16 +201,12 @@ static int wcnss_download_nv(struct wcnss_ctrl *wcnss, bool *expect_cbc)
201201
{
202202
const struct firmware *fw;
203203
struct device *dev = wcnss->dev;
204+
struct wcnss_download_nv_req *req;
204205
const char *nvbin = NVBIN_FILE;
205206
const void *data;
206207
ssize_t left;
207208
int ret;
208209

209-
struct wcnss_download_nv_req *req __free(kfree) = kzalloc(sizeof(*req) + NV_FRAGMENT_SIZE,
210-
GFP_KERNEL);
211-
if (!req)
212-
return -ENOMEM;
213-
214210
ret = of_property_read_string(dev->of_node, "firmware-name", &nvbin);
215211
if (ret < 0 && ret != -EINVAL)
216212
return ret;
@@ -224,11 +220,15 @@ static int wcnss_download_nv(struct wcnss_ctrl *wcnss, bool *expect_cbc)
224220
data = fw->data;
225221
left = fw->size;
226222

223+
req = kzalloc_flex(*req, fragment, NV_FRAGMENT_SIZE);
224+
if (!req)
225+
return -ENOMEM;
226+
227+
req->frag_size = NV_FRAGMENT_SIZE;
227228
req->hdr.type = WCNSS_DOWNLOAD_NV_REQ;
228-
req->hdr.len = sizeof(*req) + NV_FRAGMENT_SIZE;
229+
req->hdr.len = struct_size(req, fragment, NV_FRAGMENT_SIZE);
229230

230231
req->last = 0;
231-
req->frag_size = NV_FRAGMENT_SIZE;
232232

233233
req->seq = 0;
234234
do {
@@ -264,6 +264,7 @@ static int wcnss_download_nv(struct wcnss_ctrl *wcnss, bool *expect_cbc)
264264

265265
release_fw:
266266
release_firmware(fw);
267+
kfree(req);
267268

268269
return ret;
269270
}

0 commit comments

Comments
 (0)