From patchwork Tue Sep 18 23:25:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10605013 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B34A2157B for ; Tue, 18 Sep 2018 23:25:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A31602BE8A for ; Tue, 18 Sep 2018 23:25:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9605C2BE8E; Tue, 18 Sep 2018 23:25:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 370142BE8A for ; Tue, 18 Sep 2018 23:25:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726988AbeISFAH (ORCPT ); Wed, 19 Sep 2018 01:00:07 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:42027 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726960AbeISFAH (ORCPT ); Wed, 19 Sep 2018 01:00:07 -0400 Received: by mail-pf1-f196.google.com with SMTP id l9-v6so1732814pff.9 for ; Tue, 18 Sep 2018 16:25:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=Zl/oD37QBXSB6GaKlveKuws8075DDhvJy03Z2CKa8Ic=; b=brP0eGeEJHJSEoTXy6/yuI9fNI8P+Sq2VB/3dC9/WTrMgwUOj1ofG4xOXy6OP6/NSu j304Qf2ExV6px3GoXjnFthqwBItIRosvFfw5RT92SmOetFxr0aipQBdzedw+ZDY2QCPF /mrfF/EKUlOWXtjSB8aBVJgTl4o4dXUUyV+mM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Zl/oD37QBXSB6GaKlveKuws8075DDhvJy03Z2CKa8Ic=; b=R729IO0Ax9mLlx7yMYs1C/s/sh5w2t6ZXMXBJPgnj+Av/ewnLU69Xv9GMocu92hsvO yaW+fLmLs05UdHq0dK1Y3p5r3yHLqErlGQrVdiIv9wn7w4oI2O25S3Zs85jxm8hRp421 3kwXOUYJzGdlCoV2UXezmP3EG5AyflIcGer9kkmi47+ho42Nzztey7vYeU39FRfPpRJf eJMODHBQ9ZiWfkjEZ+VZlrTWPlQ6U2KWiYH96b8DTuSAvH6hK8AxGD+k4Urdo1FxSzUz rZlIQOJcVCT8DDF45bzA9Vvuf+eZxKN2LEpHgD6+ENiFD7NQ6IclROwgSAxajhmUuXzg AWDA== X-Gm-Message-State: APzg51ASsCJmdl0A+nhwB5QrPT/POfVwfHFi0sJINKBpf2mBXuhHOmxp +w22s2qEDPCGzVKZ0PHXa4N1Wg== X-Google-Smtp-Source: ANB0Vdb9DcaNcWM/bJfHrxH0ukWddCPHeS48ZgKVtyapRJ8jmQmi8bf2p2P4BXrVqTvVGb/3ciJuFA== X-Received: by 2002:a65:5304:: with SMTP id m4-v6mr30180149pgq.250.1537313111946; Tue, 18 Sep 2018 16:25:11 -0700 (PDT) Received: from localhost.localdomain ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id p19-v6sm38366939pgh.60.2018.09.18.16.25.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 18 Sep 2018 16:25:11 -0700 (PDT) From: Linus Walleij To: Hans Ulli Kroll , Florian Fainelli , linux-usb@vger.kernel.org, Greg Kroah-Hartman Cc: linux-arm-kernel@lists.infradead.org, Linus Walleij , Dan Carpenter Subject: [PATCH] usb: host: fotg2: Fix potential NULL dereference Date: Tue, 18 Sep 2018 16:25:06 -0700 Message-Id: <20180918232506.29857-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is code in the .remove() hook to handle the drvdata being NULL, for good reasons: it is never set, so it will always be NULL. As I moved code around, static checkers start complaining. Instead of this, make sure to always set it on successful probe so we can always dereference it on the remove path. Use the platform_device_[set|get]_drvdata() since this is a platform device. Fixes: ffa8a31b5b3b ("usb: host: fotg2: add silicon clock handling") Reported-by: Dan Carpenter Cc: Dan Carpenter Signed-off-by: Linus Walleij --- drivers/usb/host/fotg210-hcd.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/usb/host/fotg210-hcd.c b/drivers/usb/host/fotg210-hcd.c index 058ff82ea789..bbcc68179bfc 100644 --- a/drivers/usb/host/fotg210-hcd.c +++ b/drivers/usb/host/fotg210-hcd.c @@ -5636,6 +5636,7 @@ static int fotg210_hcd_probe(struct platform_device *pdev) goto failed_dis_clk; } device_wakeup_enable(hcd->self.controller); + platform_set_drvdata(pdev, hcd); return retval; @@ -5656,16 +5657,12 @@ static int fotg210_hcd_probe(struct platform_device *pdev) */ static int fotg210_hcd_remove(struct platform_device *pdev) { - struct device *dev = &pdev->dev; - struct usb_hcd *hcd = dev_get_drvdata(dev); + struct usb_hcd *hcd = platform_get_drvdata(pdev); struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); if (!IS_ERR(fotg210->pclk)) clk_disable_unprepare(fotg210->pclk); - if (!hcd) - return 0; - usb_remove_hcd(hcd); usb_put_hcd(hcd);