From patchwork Wed Mar 3 19:26:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 392653 Delivered-To: patch@linaro.org Received: by 2002:a02:290e:0:0:0:0:0 with SMTP id p14csp5615224jap; Wed, 3 Mar 2021 17:58:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJwDFZ1oKw9YgF+p5cdDa7emnt96FBt+RM9XhfWd8f6VvKvI9LF2sYv1Y3dpcoQ+biodD+OI X-Received: by 2002:a05:6402:b70:: with SMTP id cb16mr1907656edb.11.1614822772284; Wed, 03 Mar 2021 17:52:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614822772; cv=none; d=google.com; s=arc-20160816; b=QPOotZ+l76ai9XJOatI/6RLw92KgJMtcJqypNz+rV84hKt6JbzcEHfUx0TbqJ4kuqq 7Joo5qgYugVpz1iWIcgd6+0Xf6RXGCKPMcoGBTrAlvQZZpzsSGAiEbdtokvhhib/IWRR T7xnMXXvNxKE2DRPj93aarNRkwya9R7VylhsURM1LEhs+x/wAAd6cM7w7iQ7yLwlgb/J PV0fPUW8VQdf8gKxCqQN/eJIjcnDylltQqQq5TMmbU0E6qlQH+gbn1BqII4ginVFry8o gh9M6Q/noQVP6mpEAJWnOrz3omofolJUhgf3zj22Bj/r88PvXEpK9mqcmw/92HNIfw0N P1Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=CpnUMvWVOJdi34gV5Xr4CO6KXX8Go12ukZ8hFpNKPao=; b=msaQGafDNn4MJicES7eg/3pfYT2O/9lnHSbcam31qUoyZICz75D4IysB6//gTF3ucD K2oQ6uep4vkJSkTsyneT7cJtukB1T6s7wcyV5p2R5K42MyJXxxdhOPFdi/MinWAAggZ7 tGPwCLrQxNVGshAm+gtfdTjb3l7yKwSjkUOwbcZ5H3e3w0FdsBIX5UaGQJyXgh9t+pGb BBxIL80usiD6F5YkXeYQ+ITmF74PPOjnWMQEC9J8Jw0otw16NObomxhtxTGfC600UPjB fcqdzHigSW+Ceulrsk6SE/pYWK5gq54QgEAoa06j9OFuIe/iEr4uI5XWxjJSzzkYn9Yu +Gyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RT6QttOz; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-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. [23.128.96.18]) by mx.google.com with ESMTP id p17si16189393ejd.307.2021.03.03.17.52.52; Wed, 03 Mar 2021 17:52:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RT6QttOz; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-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 S1389874AbhCCVs1 (ORCPT + 16 others); Wed, 3 Mar 2021 16:48:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234075AbhCCTZp (ORCPT ); Wed, 3 Mar 2021 14:25:45 -0500 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB2C7C061756 for ; Wed, 3 Mar 2021 11:25:01 -0800 (PST) Received: by mail-oi1-x233.google.com with SMTP id q203so4211728oih.5 for ; Wed, 03 Mar 2021 11:25:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=CpnUMvWVOJdi34gV5Xr4CO6KXX8Go12ukZ8hFpNKPao=; b=RT6QttOzOrQM2tUqzZTRK1txLRiMMB/svOEsSWmZ+y7f7nABd0aMhQkUI8GYStp298 EAmOSPeAWegHzMOAiTV524x+Ez6TIeFsukC5qZO1kY48OhJNl2AIcfGvJRhVyn+NPc+s 9H+pyZuoslkMUlyTSPRhsN5YPyo4YYD67s9A9dbMX7xja4ntGeyJTKSv9erHMtBiW41A gtxrY2AhPRo/2eU+9fuIlthySu43aGBHs9nXclRlpdL2qfqADr3bNY6wvSBv6IHMDHVM 31kS/5z3hVXbF2tL3w3ZhS7RCQh3nXq5/Ojtm9nDKI7EAL8U57gVW2SprC7wEShI1qhf bZ+Q== 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:mime-version :content-transfer-encoding; bh=CpnUMvWVOJdi34gV5Xr4CO6KXX8Go12ukZ8hFpNKPao=; b=AWNEpPa396Kj45gIXJzP2T3m5BLI8wSCyJtdnY81lnXxmF4MHHTC8rQE7pwxQsE2Qd Yg9mORHpQTpogC+KlPUrApwKrNImRoZAObTU/3uxEZgGnSJBGAarNqdzpZ/IDj1IG7CD 9OraILjEYjaGWjxhppQ6Cj3/bkTIY2dWATIhZ+cFqC3kO0b6Kc0aKofdbUW4BbNKQLES 3BM4EnmsAWQ7UG8+ECPFG2rPqbQL7mtBsP4SMwXH2N7NzYIrdjZjXuMIBEu3MHsMKwrY lTa7VefVDXcQYsYD4qNrxe/Yz5xe/Wo+cEee4ZHDL5NiS/pF3okibxEGzeMuEuQtgjZr X7UA== X-Gm-Message-State: AOAM5338nhC2ou1tg41n5lX1KO8CKK9KPrqDsvkHzG9h0Jmw1OETTglp E69QtsU7XvDr1zcYVQUfUOvDnA== X-Received: by 2002:aca:683:: with SMTP id 125mr304319oig.172.1614799500958; Wed, 03 Mar 2021 11:25:00 -0800 (PST) Received: from localhost.localdomain (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id n17sm2965762oos.20.2021.03.03.11.25.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Mar 2021 11:25:00 -0800 (PST) From: Bjorn Andersson To: Felipe Balbi , Greg Kroah-Hartman , Ray Chi Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH] usb: dwc3: Flip condition guarding power_supply_put() Date: Wed, 3 Mar 2021 11:26:14 -0800 Message-Id: <20210303192614.759729-1-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The condition guarding the power_supply_put() calls in error and removal paths are backwards, resulting in a guaranteed NULL pointer dereference if no power supply was acquired. Fixes: 59fa3def35de ("usb: dwc3: add a power supply for current control") Signed-off-by: Bjorn Andersson --- drivers/usb/dwc3/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.29.2 diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index d15f065849cd..94fdbe502ce9 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1628,7 +1628,7 @@ static int dwc3_probe(struct platform_device *pdev) assert_reset: reset_control_assert(dwc->reset); - if (!dwc->usb_psy) + if (dwc->usb_psy) power_supply_put(dwc->usb_psy); return ret; @@ -1653,7 +1653,7 @@ static int dwc3_remove(struct platform_device *pdev) dwc3_free_event_buffers(dwc); dwc3_free_scratch_buffers(dwc); - if (!dwc->usb_psy) + if (dwc->usb_psy) power_supply_put(dwc->usb_psy); return 0;