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: 146948 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp16604ljw; Tue, 18 Sep 2018 16:25:14 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYly9/2vIrJojed5BQsPA7KNQtVtajRNr08IxUVeHsSJP7+Qzc/dTAaWhRR8aKARpoebEa8 X-Received: by 2002:a62:59d5:: with SMTP id k82-v6mr32737424pfj.143.1537313113966; Tue, 18 Sep 2018 16:25:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537313113; cv=none; d=google.com; s=arc-20160816; b=IoFTlNel1lpE+E39Lahq1Ih+0JAVa3bvb+kvkXniX0jsaJQ4Yxh191k156tMEdFe4z UhLBUdmZikP3pcTwfThrsJaYRkaHYP7XaklNJsbX2od10Aicwkvw5C0y+3L1LLgjfItn 976ZE1Qc6uDEsrtdQDPywBhS1RB08cp/qEgkT/WMPY/GUdqfeAGNw2CeYBQXzISCgdhn 0h7E311/FGBakgSjb0oCZm+S/dmCZu2g5gsXO5Q0o4JNGsjFQb6WZchoJC/1NQ91U0rJ lR78rgsKbuD0mIfK3zfr3IRxIgduGHafTOR974KeqfnT3exwVe+g3x0Q1RS0w45V/sCu 1gCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=Zl/oD37QBXSB6GaKlveKuws8075DDhvJy03Z2CKa8Ic=; b=tTuxvqLNxfANar0ZDOW2z2Js8VlJMLHrpne60Yb0hGz6b+uDt5ttCVaybeAm46GXnF w7TqfYfChwGSCHnEVBSsrgK3Miva1JdFZsiiXER2ga2wbhjD+pNIaGB2mma4xmBpwQ0X O211xQaJVMpBO4ywUCTkSECdOOla74vyIW+Qt52B6Sgf2mEqPkeCPOlnkwCJtyQEzUso gLNeoDDE7igoKGqOV8cTLSS6oL8xvrQqSgTXV6DxDDOsqHhcaJkMD5G+aVNzu3Z3nk+W u5otaQ0qEDhVE1BnVTYVgK5Z5suWeBqJgaVagqT4kq+NgGUEXwkQ1wDY/wI2vDvFYQcR 3QAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=brP0eGeE; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1-v6si19024301plk.294.2018.09.18.16.25.13; Tue, 18 Sep 2018 16:25:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=brP0eGeE; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726988AbeISFAH (ORCPT + 5 others); 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-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 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(-) -- 2.17.1 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);