Received: by 10.213.65.68 with SMTP id h4csp691898imn; Thu, 22 Mar 2018 06:36:46 -0700 (PDT) X-Google-Smtp-Source: AG47ELvT8InrwHA49R8cwcS/L7lJdeixIaKoX8qDiUto2wijkL7tgw6ko6ARRg6ERaqz1yshyS4w X-Received: by 2002:a17:902:2e:: with SMTP id 43-v6mr25115575pla.282.1521725806096; Thu, 22 Mar 2018 06:36:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521725806; cv=none; d=google.com; s=arc-20160816; b=w1k/vyAaYlYtflBe8O6rU1Ck+7th4ovzAUqZciIFsI8ala4sqJCRNGM2TqK/DiP/y4 EqyHhWFZxqoqgM30M94rsgHORGmh8p+ThBU3fegVxwB5sjALm0sJP0xdCcWdlNyPyFv/ zgBV0MDI86fyApO1OYJwvRG6Qg6zR6kRaSB8TPxDrqLgtbUh6PccU596F5frnHkGHF8g vhT0KPyOENLS9rVwBcWDoFKGUKZv5nY6s8df9uUC1bpsIV0Y0augZZYzkLpipEy/iJ+3 DyNS9RmIK57zJRuJZ8dHHi5ijN7uQFHkVpMJnIR643mXUo8vLFsiwxDKmR4D9MSE2LBz /u+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=ymOIUPuAq7LqDXgvAzq52crszN+b+dul2WLfSiayWQk=; b=HeVP1VyLHx6uOZD3aY8FxHQNe9gUVeaMxqjpAb17Yu52YzqTD6OKX1Ekl3+3HTJ0DX S/8E5RGKWoTAQXn14COsudaKbQaqTU8WzQEj0/omIAS2u2CBBqvDCKQLQvJBUidZXWL7 a/XeBF6fj2hafLZqyYSLyScgFLE82OLcs7PENaS3/kHVc2RC2dcauzxl/A5NH/BwMzH/ VeNSCA5TWYTyPHhLc9pi8FrnRAQxWrL7yOm179BZCoH9fFIX8Kk6ud5LIcu0V3cHoCUJ tzG88u92Vs+YDhZaf9yXNgJqfDvQ+PFFsmwjfQkhb+7ajAUDrxRnFGn2NG4D80b903XJ vvXA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33-v6si6277893ply.517.2018.03.22.06.36.30; Thu, 22 Mar 2018 06:36:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755522AbeCVNeS (ORCPT + 99 others); Thu, 22 Mar 2018 09:34:18 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:36904 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753626AbeCVNeQ (ORCPT ); Thu, 22 Mar 2018 09:34:16 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tomeu) with ESMTPSA id 13CEF272292 Subject: Re: [PATCH v3] usb: dwc2: dwc2_vbus_supply_init: fix error check To: =?UTF-8?Q?Heiko_St=c3=bcbner?= Cc: linux-kernel@vger.kernel.org, Felipe Balbi , Amelie Delaunay , Minas Harutyunyan , Greg Kroah-Hartman , linux-usb@vger.kernel.org References: <20180322093943.49717-1-tomeu.vizoso@collabora.com> <20180322131451.12631-1-tomeu.vizoso@collabora.com> <1794463.c121CNJ3R4@diego> From: Tomeu Vizoso Message-ID: Date: Thu, 22 Mar 2018 14:34:10 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1794463.c121CNJ3R4@diego> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/22/2018 02:26 PM, Heiko Stübner wrote: > Am Donnerstag, 22. März 2018, 14:14:51 CET schrieb Tomeu Vizoso: >> devm_regulator_get_optional returns -ENODEV if the regulator isn't >> there, so if that's the case we have to make sure not to leave -ENODEV >> in the regulator pointer. >> >> Also, make sure we return 0 in that case, but correctly propagate any >> other errors. Also propagate the error from _dwc2_hcd_start. >> >> Fixes: 531ef5ebea96 ("usb: dwc2: add support for host mode external vbus >> supply") Cc: Amelie Delaunay >> Signed-off-by: Tomeu Vizoso >> >> --- >> >> v2: Only overwrite the error in the pointer after checking it (Heiko >> Stübner ) >> v3: Remove hunks that shouldn't be in this patch >> --- >> drivers/usb/dwc2/hcd.c | 11 +++++++---- >> 1 file changed, 7 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c >> index dcfda5eb4cac..863aed20517f 100644 >> --- a/drivers/usb/dwc2/hcd.c >> +++ b/drivers/usb/dwc2/hcd.c >> @@ -359,8 +359,13 @@ static void dwc2_gusbcfg_init(struct dwc2_hsotg *hsotg) >> static int dwc2_vbus_supply_init(struct dwc2_hsotg *hsotg) >> { >> hsotg->vbus_supply = devm_regulator_get_optional(hsotg->dev, "vbus"); >> - if (IS_ERR(hsotg->vbus_supply)) >> + if (PTR_ERR(hsotg->vbus_supply) == -ENODEV) { >> + hsotg->vbus_supply = NULL; >> return 0; >> + } else if (IS_ERR(hsotg->vbus_supply)) { >> + hsotg->vbus_supply = NULL; >> + return PTR_ERR(hsotg->vbus_supply); >> + } > > my personal cluelessnes, but can you use PTR_ERR without checking for > IS_ERR first? It's just a cast, so it should be fine. > I would've expected something along the line of > > if (IS_ERR(hsotg->vbus_supply)) { > if (PTR_ERR(hsotg->vbus_supply) == -ENODEV) { > hsotg->vbus_supply = NULL; > return 0; > } else { > return PTR_ERR(hsotg->vbus_supply); > } > } I kind of liked to avoid one indentation level. Also wanted to play safe and NULLify the pointer in both code paths. Thanks, Tomeu