rpmsg: glink: Add check for kstrdup
authorJiasheng Jiang <jiasheng@iscas.ac.cn>
Mon, 19 Jun 2023 03:06:31 +0000 (11:06 +0800)
committerBjorn Andersson <andersson@kernel.org>
Sat, 15 Jul 2023 21:59:30 +0000 (14:59 -0700)
Add check for the return value of kstrdup() and return the error
if it fails in order to avoid NULL pointer dereference.

Fixes: b4f8e52b89f6 ("rpmsg: Introduce Qualcomm RPM glink driver")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Link: https://lore.kernel.org/r/20230619030631.12361-1-jiasheng@iscas.ac.cn
Signed-off-by: Bjorn Andersson <andersson@kernel.org>
drivers/rpmsg/qcom_glink_native.c

index 2db82f6..e10c05e 100644 (file)
@@ -227,6 +227,10 @@ static struct glink_channel *qcom_glink_alloc_channel(struct qcom_glink *glink,
 
        channel->glink = glink;
        channel->name = kstrdup(name, GFP_KERNEL);
+       if (!channel->name) {
+               kfree(channel);
+               return ERR_PTR(-ENOMEM);
+       }
 
        init_completion(&channel->open_req);
        init_completion(&channel->open_ack);