Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp563475img; Mon, 18 Mar 2019 09:11:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqwE06X9o5QYpO9r2aLlZsN+B0PONKyGCDivBmvO+wzcR7KvtWB/BBSZo/JUz5zMPofTYNno X-Received: by 2002:a63:d209:: with SMTP id a9mr18309303pgg.341.1552925517868; Mon, 18 Mar 2019 09:11:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552925517; cv=none; d=google.com; s=arc-20160816; b=jpMl8zRjVV764oneaK2QiXRCV8095PPoUe7IJyQHobV2hDkkJNQdbdR134ijYNmnDL D5mPhCJ3uqDplweBC5XdtCumKKlzadi24/5Uu+hh/FtM1h9ArEImL0H24qfNxdruNeK3 pIbVSko9nINHxh+3d+uNVeMpKFSEbuj9pfGfqfd/dOYXbTCVFrpQON0q/aBuNrig6MMd eWISw6kfsQkWR231ipGUHceni2XpLxg3iFz48wC3hnYQtUw8O2tXieuNAYcWNnqujUA5 Fje5w42p7vqNr73AHYPxxadc+I810g/zx1pWgjwak18UnhIzLjhVUWCd9K5o4r6Vq4ob UKag== 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:references:cc:to:from:subject:dkim-signature; bh=YIhFIKs9el8j4hsLgwZPPQzsqFgxi9CCkwroXgIH/9M=; b=h3riix0u658c1HHsdsb2LRo52Gia6Q11C40htaRbcxv4yzh6c3INyMSpD9kgJxEDlB 9mmD0w+lzfWC+2PqGpvZulU/eZnFluRUVJD4AB3Y5avc2mmt3XHUJAmQU4BzjKxtAzyk se0N2tVPNY5J3vHuA6mu/qSA4df+vIkx0pNVKNTHb4Sm93s14Ds+uZZ0Ep6a+KVhtnPh WcbQb2ImTxF20J9ahgFfFjgUMjZT9HX2M+uvh8HOhuFYYUXb4sYG/Sc7gswQicxOgE9z DIuizTlVjHM5t2Rpntfo151Y7kmk0wfkqnhyCW4nWktouMdyHiFcP9+KYtyXI8HM/2dZ MLyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="H5y/fWrh"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o5si8860372pgp.496.2019.03.18.09.11.40; Mon, 18 Mar 2019 09:11:57 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b="H5y/fWrh"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727529AbfCRQKe (ORCPT + 99 others); Mon, 18 Mar 2019 12:10:34 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:44059 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726806AbfCRQKd (ORCPT ); Mon, 18 Mar 2019 12:10:33 -0400 Received: by mail-pg1-f196.google.com with SMTP id h34so11686801pgh.11 for ; Mon, 18 Mar 2019 09:10:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=YIhFIKs9el8j4hsLgwZPPQzsqFgxi9CCkwroXgIH/9M=; b=H5y/fWrhJ8CUuu3ZQwAI2HU4xEuhAC+4HrZUlSOvBKFSTZkUnylfiXszr7uJhr0FDK DMaw8/oALs88yoM8a63/MpI6bVM46oIs7iwdKG0AohB0l/RB6VSEF8Im5waolXk7wB8r Ya17B2Ndyg/9tvs4+oJtd69z3GTE5nJzNNwz4r7zOGpfq00u5Or+zndAZUHKGO1gn8ws 39XIUyeRBXo7KFvjLFXIqax6waEHcwwFY/TNvf+sB4EjmpwhctvyrDFtYNoP6RSsIvg0 VRbCEvrGdkicz3ovf/StnTCYTPlwygehzfoU3AfXaZ15p245VmINWF8DpCE7VfEt0aja m55Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=YIhFIKs9el8j4hsLgwZPPQzsqFgxi9CCkwroXgIH/9M=; b=LZdgsfvJnKnLvmS3c3gqiduhXk2rokQ+5AypXnx2qbUCVsDtSefp3/zFvh1hXLVnPi nrrkSCKWaOEGsC0aDEWjubhBMeNeJB83+JiAgb0b8wC0nAPZQpcy1bztlCqGwVey18K0 DANmOgArg7Px5bRjCj+urc7DZ1x3piZG5pcwMPJBuMFGHZRhG/4lOWVIuXxMYA57v2xP Wj7Oxw0Xt9GgwQ0rrPtBsGIfPOWxdss2bH5rP6isgMsG+2FwJLWYECTZFAGgfy6RmNHp 31hfUGbKkZ3EiHHemfiwgYJxigx/8UxHHf0aRel7f11S3OvoZioBGT4I9URokwHlxDxm 6prw== X-Gm-Message-State: APjAAAU+IDFWqVOa3AlAIUzq762bglcApD0rk7IrPMbz7eQK3DGIWFIG +1s+gxcUD/k5twVWsY+MaFU= X-Received: by 2002:a17:902:547:: with SMTP id 65mr20691370plf.242.1552925432769; Mon, 18 Mar 2019 09:10:32 -0700 (PDT) Received: from [192.168.2.145] (ppp94-29-37-86.pppoe.spdop.ru. [94.29.37.86]) by smtp.googlemail.com with ESMTPSA id m8sm22805463pgr.82.2019.03.18.09.10.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Mar 2019 09:10:31 -0700 (PDT) Subject: Re: [PATCH] regulator: core: fix error path for regulator_set_voltage_unlocked From: Dmitry Osipenko To: Steve Twiss , Liam Girdwood , Mark Brown Cc: LKML , Maciej Purski , Support Opensource References: <20190318155054.59B483FBD8@swsrvapps-01.diasemi.com> <513a7028-b972-a821-7bf1-0e105bf71305@gmail.com> Message-ID: Date: Mon, 18 Mar 2019 19:10:23 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <513a7028-b972-a821-7bf1-0e105bf71305@gmail.com> Content-Type: text/plain; charset=utf-8 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 18.03.2019 19:03, Dmitry Osipenko пишет: > 18.03.2019 18:32, Steve Twiss пишет: >> During several error paths in the function >> regulator_set_voltage_unlocked() the value of 'ret' can take on negative >> error values. However, in calls that go through the 'goto out' statement, >> this return value is lost and return 0 is used instead, indicating a >> 'pass'. >> >> There are several cases where this function should legitimately return a >> fail instead of a pass: one such case includes constraints check during >> voltage selection in the call to regulator_check_voltage(), which can >> have -EINVAL for the case when an unsupported voltage is incorrectly >> requested. In that case, -22 is expected as the return value, not 0. >> >> Fixes: 9243a195be7a ("regulator: core: Change voltage setting path") >> Signed-off-by: Steve Twiss >> --- >> drivers/regulator/core.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c >> index 68473d0..caf8743 100644 >> --- a/drivers/regulator/core.c >> +++ b/drivers/regulator/core.c >> @@ -3326,7 +3326,7 @@ static int regulator_set_voltage_unlocked(struct regulator *regulator, >> goto out2; >> >> out: >> - return 0; >> + return ret; >> out2: >> voltage->min_uV = old_min_uV; >> voltage->max_uV = old_max_uV; >> > > Looks like a good catch. > > Probably will be a bit better to write this as: > > /* for not coupled regulators this will just set the voltage */ > ret = regulator_balance_voltage(rdev, state); > - if (ret < 0) > - goto out2; > - > + if (ret < 0) { > + voltage->min_uV = old_min_uV; > + voltage->max_uV = old_max_uV; > + } > out: > - return 0; > -out2: > - voltage->min_uV = old_min_uV; > - voltage->max_uV = old_max_uV; > - > return ret; > } > Also, probably won't hurt to add a stable tag "Cc: stable " to get the fix backported.