From 63a32bf3617369ad3546241a57753bebcbf67631 Mon Sep 17 00:00:00 2001 From: Prashanth K Date: Fri, 28 Apr 2023 12:37:42 +0530 Subject: [PATCH] usb: gadget: f_gsi: bail out if opts is null Currently, functions gsi_inst_clean & gsi_free_inst utilises gsi_opts without any check, however there is a possibility that the opts structure could become NULL. In such case, due to lack of if checks can result in NULL pointer dereference. Change-Id: I548690e2eee377b5292f258972ae7e38417f3085 Signed-off-by: Prashanth K --- drivers/usb/gadget/function/f_gsi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/f_gsi.c b/drivers/usb/gadget/function/f_gsi.c index 1111b88c6516..fcfe9a9bdced 100644 --- a/drivers/usb/gadget/function/f_gsi.c +++ b/drivers/usb/gadget/function/f_gsi.c @@ -3849,6 +3849,9 @@ static struct config_item_type gsi_func_rmnet_type = { static void gsi_inst_clean(struct gsi_opts *opts) { + if (!opts) + return; + if (opts->gsi->c_port.cdev.dev) { struct cdev *cdev = &opts->gsi->c_port.cdev; struct f_gsi *gsi = opts->gsi; @@ -3962,7 +3965,7 @@ static void gsi_free_inst(struct usb_function_instance *f) enum ipa_usb_teth_prot prot_id; struct f_gsi *gsi; - if (!opts->gsi) + if (!opts || !opts->gsi) return; prot_id = opts->gsi->prot_id;