From patchwork Mon Oct 8 00:46:09 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yongjun X-Patchwork-Id: 1563351 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id A06D13FC1A for ; Mon, 8 Oct 2012 00:46:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752006Ab2JHAqL (ORCPT ); Sun, 7 Oct 2012 20:46:11 -0400 Received: from mail-qa0-f46.google.com ([209.85.216.46]:45263 "EHLO mail-qa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751519Ab2JHAqK (ORCPT ); Sun, 7 Oct 2012 20:46:10 -0400 Received: by mail-qa0-f46.google.com with SMTP id c26so1733797qad.19 for ; Sun, 07 Oct 2012 17:46:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=bW6JuWIrtlJGgSPksyWefyq8K44mDxnECjk2j1AGZqs=; b=QJHqGmRJo7buu4hJKFaejWPOV6lko+iea26ltwkzEe8ufklZXcry3agPjj5ulazB8S tW/oGB1JqrMc9nfttbN6wD8W9yJoUndOLhOu1TpKR9Sq+70XNw89BgznK6Sca6d1BReb MUdNfQxw7bsJx+E6O1hvJz29/O6ZyvK1cU7uE2mYe4HEGe70KucDGY29Olb/auctxkhD LvS1Oj3NfNeiz46YbAiSZvIs8yYCpgJRinMiGNwMkv9AiwlVdF9NMNWuUUKVjoitZJNz 87vemXNpQemgyt9hDYwaF19WPCfUASegeYxQZhcEX+fzBThm5lrA9J38w7L/mPtZAU0B 8nMA== MIME-Version: 1.0 Received: by 10.49.85.202 with SMTP id j10mr39538092qez.59.1349657169698; Sun, 07 Oct 2012 17:46:09 -0700 (PDT) Received: by 10.229.146.194 with HTTP; Sun, 7 Oct 2012 17:46:09 -0700 (PDT) Date: Mon, 8 Oct 2012 08:46:09 +0800 Message-ID: Subject: [PATCH] usb: otg: isp1301_omap: fix potential NULL pointer dereference From: Wei Yongjun To: balbi@ti.com, gregkh@linuxfoundation.org Cc: yongjun_wei@trendmicro.com.cn, linux-usb@vger.kernel.org, linux-omap@vger.kernel.org Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org From: Wei Yongjun The dereference should be moved below the NULL test. dpatch engine is used to auto generate this patch. (https://github.com/weiyj/dpatch) Signed-off-by: Wei Yongjun --- drivers/usb/otg/isp1301_omap.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/usb/otg/isp1301_omap.c b/drivers/usb/otg/isp1301_omap.c index ceee211..3a1f8e2 100644 --- a/drivers/usb/otg/isp1301_omap.c +++ b/drivers/usb/otg/isp1301_omap.c @@ -1279,9 +1279,13 @@ static int isp1301_otg_enable(struct isp1301 *isp) static int isp1301_set_host(struct usb_otg *otg, struct usb_bus *host) { - struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); + struct isp1301 *isp; - if (!otg || isp != the_transceiver) + if (!otg) + return -ENODEV; + + isp = container_of(otg->phy, struct isp1301, phy); + if (isp != the_transceiver) return -ENODEV; if (!host) { @@ -1335,9 +1339,13 @@ isp1301_set_host(struct usb_otg *otg, struct usb_bus *host) static int isp1301_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) { - struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); + struct isp1301 *isp; + + if (!otg) + return -ENODEV; - if (!otg || isp != the_transceiver) + isp = container_of(otg->phy, struct isp1301, phy); + if (isp != the_transceiver) return -ENODEV; if (!gadget) { @@ -1415,11 +1423,14 @@ isp1301_set_power(struct usb_phy *dev, unsigned mA) static int isp1301_start_srp(struct usb_otg *otg) { - struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); + struct isp1301 *isp; u32 otg_ctrl; - if (!otg || isp != the_transceiver - || isp->phy.state != OTG_STATE_B_IDLE) + if (!otg) + return -ENODEV; + + isp = container_of(otg->phy, struct isp1301, phy); + if (isp != the_transceiver || isp->phy.state != OTG_STATE_B_IDLE) return -ENODEV; otg_ctrl = omap_readl(OTG_CTRL); @@ -1443,10 +1454,13 @@ static int isp1301_start_hnp(struct usb_otg *otg) { #ifdef CONFIG_USB_OTG - struct isp1301 *isp = container_of(otg->phy, struct isp1301, phy); + struct isp1301 *isp; u32 l; - if (!otg || isp != the_transceiver) + if (!otg) + return -ENODEV; + isp = container_of(otg->phy, struct isp1301, phy); + if (isp != the_transceiver) return -ENODEV; if (otg->default_a && (otg->host == NULL || !otg->host->b_hnp_enable)) return -ENOTCONN;