Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp440640pxb; Wed, 18 Aug 2021 06:04:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxYj8DGnEhWEgVlKSTgxnSAOnYaE8Ml+x95b0OmDDz7zeAfAaSiRm1Kmgg3rifFNPu4wCY X-Received: by 2002:a92:d24b:: with SMTP id v11mr6074256ilg.218.1629291844126; Wed, 18 Aug 2021 06:04:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629291844; cv=none; d=google.com; s=arc-20160816; b=ySVmSLIYqo96Oxu/JCkONYPZez4FioEA4bn0tNCCospe4JWi3FFtTxuhO9WthcsIOt c8wlrhaDqRyCu+vpgBymiKODTk9SOwlcSUFgSN2IblY/yB2FOXsUExlAhL/grsaSmNEo 5KN8WNSZ69N9yTn47JQ73TuCVt7TDeU11rHfL3lMpwRTRpdBMIJOO50WJj77U0RtaIZ6 rh2e/3yye0fyrSQGfpqRWU1fPk30C123qKJcAYrL+jcq4N5b0JDyBONn9sK5UVCnxnzM nsNsVkLOjNxLVAu/bia46N3d+J7POUXStVgDGJXs13L8q/mhDDzciOpfJzQXl4fo4g5x nb5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=OvhHsahKbeL/oehAzIE+3omGO0SurMUI5JnKyvUak+Y=; b=UREEd81YTwP0EhlEYC4ypWrLd+0NoVmh7neSF0+qzsbiEDPegzgLWLCHIF3GrdJXY3 SfX2GM5Y1UEHbCCbqimJhZFOK//8aOqBAUOX0rT2x+0HRElwHD/CjZyrRh0/oruqegMk AmcMpAJEOjkvUuyvi5XnZcADE38Yf27OTMcJ0Q4kXgwv3a2rs8MP83BA3ZL8pfyxdmOT XG6mm/UsEotUekm9TPtbd2vebnhEJTCm/2w8KTU8R4JA8GoDKwP+3FzGI2hPkbs1bJBf 5NiW1o1RuG2bew/HuYOvH++mL2CIZ+t16Wr293oTHVdZAvPVkfI6U/lffSy9nPY/BE88 7ENQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r28si5253802jao.16.2021.08.18.06.03.38; Wed, 18 Aug 2021 06:04:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234949AbhHRNCq (ORCPT + 99 others); Wed, 18 Aug 2021 09:02:46 -0400 Received: from mail.ispras.ru ([83.149.199.84]:53758 "EHLO mail.ispras.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235423AbhHRNCp (ORCPT ); Wed, 18 Aug 2021 09:02:45 -0400 Received: from kleverstation.intra.ispras.ru (unknown [10.10.2.220]) by mail.ispras.ru (Postfix) with ESMTPS id B40B740A2BD8; Wed, 18 Aug 2021 13:02:08 +0000 (UTC) From: Nadezda Lutovinova To: Felipe Balbi Cc: Nadezda Lutovinova , Greg Kroah-Hartman , Johan Hovold , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: [PATCH] usb: gadget: mv_u3d: Change functon call in mv_u3d_probe() Date: Wed, 18 Aug 2021 16:01:35 +0300 Message-Id: <20210818130135.575-1-lutovinova@ispras.ru> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If IRQ occurs between calling request_irq() and mv_u3d_eps_init(), then null pointer dereference occurs since u3d->eps[] wasn't initialized yet but used in mv_u3d_nuke(). The patch puts registration of the interrupt handler after initializing of neccesery data. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Nadezda Lutovinova --- drivers/usb/gadget/udc/mv_u3d_core.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/usb/gadget/udc/mv_u3d_core.c b/drivers/usb/gadget/udc/mv_u3d_core.c index ce3d7a3eb7e3..a1057ddfbda3 100644 --- a/drivers/usb/gadget/udc/mv_u3d_core.c +++ b/drivers/usb/gadget/udc/mv_u3d_core.c @@ -1921,14 +1921,6 @@ static int mv_u3d_probe(struct platform_device *dev) goto err_get_irq; } u3d->irq = r->start; - if (request_irq(u3d->irq, mv_u3d_irq, - IRQF_SHARED, driver_name, u3d)) { - u3d->irq = 0; - dev_err(&dev->dev, "Request irq %d for u3d failed\n", - u3d->irq); - retval = -ENODEV; - goto err_request_irq; - } /* initialize gadget structure */ u3d->gadget.ops = &mv_u3d_ops; /* usb_gadget_ops */ @@ -1941,6 +1933,15 @@ static int mv_u3d_probe(struct platform_device *dev) mv_u3d_eps_init(u3d); + if (request_irq(u3d->irq, mv_u3d_irq, + IRQF_SHARED, driver_name, u3d)) { + u3d->irq = 0; + dev_err(&dev->dev, "Request irq %d for u3d failed\n", + u3d->irq); + retval = -ENODEV; + goto err_request_irq; + } + /* external vbus detection */ if (u3d->vbus) { u3d->clock_gating = 1; @@ -1964,8 +1965,8 @@ static int mv_u3d_probe(struct platform_device *dev) err_unregister: free_irq(u3d->irq, u3d); -err_request_irq: err_get_irq: +err_request_irq: kfree(u3d->status_req); err_alloc_status_req: kfree(u3d->eps); -- 2.17.1