Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp4943908pxb; Mon, 28 Mar 2022 06:00:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2MKbCx2O9D+sjar8ik5lDdIJm2X8tDZLJJxtsBHi3BBTy3+gnw+SeyKDTwLSRtMD63210 X-Received: by 2002:a17:902:d504:b0:154:172:3677 with SMTP id b4-20020a170902d50400b0015401723677mr26489081plg.147.1648472456431; Mon, 28 Mar 2022 06:00:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648472456; cv=none; d=google.com; s=arc-20160816; b=c+sslgh5iHZkZfZP3OrbIYumOTo+zDZsTfydxWr6FMo4SkqjlV0JgHSox90NvAWZnz JKuVFv/hSkg7O4uoycbZQFY+8abGurHkstxDTAS42zND6Oi6X7i0ReLXz8a/0EOdhZ+x ixOYtB27MZG4vMfvfS7VbusmniDdOhFxTm8xAuQmF1te30h82AOJMuyj6n4zi1ZpNV/9 Lk2ah46en/HXYXDA18fxerwC5LXwLDK97FIvf3fcqBzczkY8xPV+v5O6qUVZjtqo229/ 7YhPa7+0HPhVwSi+wd0udL7lodyjDzqCoWkqpV78pVQQ+oV5InvZr4wkhh46Sode2Dwn xHJA== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=CLfo7Ex9MG3sv4Yvu1FDuWLuSBtFUqStk/x0hZHCz/w=; b=GfK0v1rW4rUEn6kG0cPyAI4wK2xCejXW9q08wsTWf1p34H4ScphzW4n2y4X1iTpZlG W3lvtYA7q9SEr/0LzFb7B4RjXmKqEawQyEIV7oLttspWiXutI/7DOZL9g8gn0K3JVYCJ dRVPzopMNEtRGJl+Y9GnwR2StBHaflk58hk0A3cMyaduhyznOLEw2Xq4htFGVj/Xq/Cs lATdH1XVHZi64+rTsXvQi5DJRGW0srUvOm3KJgwgcIrpkEK1QuDPC2xoWtKFxR990bG1 woz98bVV3iv6zIXdYLOwN6M7GanGXdQxEJD3szSWz5FHxW9+mKYX+xvxwyb1/Oxqtktc AU9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YL+McNUS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r15-20020a63204f000000b003816043efdcsi12516600pgm.465.2022.03.28.06.00.38; Mon, 28 Mar 2022 06:00:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YL+McNUS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235890AbiC0Prq (ORCPT + 99 others); Sun, 27 Mar 2022 11:47:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235790AbiC0Pro (ORCPT ); Sun, 27 Mar 2022 11:47:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 047F935A82; Sun, 27 Mar 2022 08:46:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 810E861046; Sun, 27 Mar 2022 15:46:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C118CC340EC; Sun, 27 Mar 2022 15:46:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648395964; bh=B3ZPOyUYGQj+6qCSUleqjBCQQNBjm+6YkuHdgpSuAyw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=YL+McNUSywygkfaI557mBMAfRb0GJiv3JZRwJRHIGuweV+5a+4Xv2ENzQQjRXdPB4 CVSCQTU2esJ/zb8h2OJPHCY5fznjz6FRlpHKxUHVRjCGefXw8XlzBOTvmfAYtuyiHQ iywuzIBa82tJN68p7zn4YWzBkiVvGxMWVQbQU9+V+sRH+1Km0wczyty5P+zSNFG7Wz 25piB0hpv07m3uxR8JC8S1k24aeRLCjZ0mv547FcGfIUp28gK5D1Jv+HkRYs1/OHXh ZP0O6B2FO3KRVVVfvmlzMTezLF+EpUCnaPJtefdoW1zuV76ZXKi0qzrOU6TvIKV46J JZnL5Q3Y2jsoA== Date: Sun, 27 Mar 2022 16:53:36 +0100 From: Jonathan Cameron To: Tong Zhang Cc: Lars-Peter Clausen , Andy Shevchenko , Sean Nyekjaer , Alexandru Ardelean , Jonathan Albrieux , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] iio:imu:bmi160: disable regulator in error path Message-ID: <20220327165336.799db3ac@jic23-huawei> In-Reply-To: <20220327154005.806049-1-ztong0001@gmail.com> References: <20220318070900.2499370-1-ztong0001@gmail.com> <20220327154005.806049-1-ztong0001@gmail.com> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 27 Mar 2022 08:40:05 -0700 Tong Zhang wrote: > Regulator should be disabled in error path as mentioned in _regulator_put(). > Also disable accel if gyro cannot be enabled. > > [ 16.233604] WARNING: CPU: 0 PID: 2177 at drivers/regulator/core.c:2257 _regulator_put > [ 16.240453] Call Trace: > [ 16.240572] > [ 16.240676] regulator_put+0x26/0x40 > [ 16.240853] regulator_bulk_free+0x26/0x50 > [ 16.241050] release_nodes+0x3f/0x70 > [ 16.241225] devres_release_group+0x147/0x1c0 > [ 16.241441] ? bmi160_core_probe+0x175/0x3a0 [bmi160_core] > > Fixes: 5dea3fb066f0 ("iio: imu: bmi160: added regulator support") > Reviewed-by: Andy Shevchenko > Signed-off-by: Tong Zhang oops. Raced with you ;) Anyhow, I added the tag, so no problem. Jonathan > --- > v2: also disable accel when gyro fail to enable > v3: add tag > drivers/iio/imu/bmi160/bmi160_core.c | 20 ++++++++++++++------ > 1 file changed, 14 insertions(+), 6 deletions(-) > > diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c > index 824b5124a5f5..01336105792e 100644 > --- a/drivers/iio/imu/bmi160/bmi160_core.c > +++ b/drivers/iio/imu/bmi160/bmi160_core.c > @@ -730,7 +730,7 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi) > > ret = regmap_write(data->regmap, BMI160_REG_CMD, BMI160_CMD_SOFTRESET); > if (ret) > - return ret; > + goto disable_regulator; > > usleep_range(BMI160_SOFTRESET_USLEEP, BMI160_SOFTRESET_USLEEP + 1); > > @@ -741,29 +741,37 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi) > if (use_spi) { > ret = regmap_read(data->regmap, BMI160_REG_DUMMY, &val); > if (ret) > - return ret; > + goto disable_regulator; > } > > ret = regmap_read(data->regmap, BMI160_REG_CHIP_ID, &val); > if (ret) { > dev_err(dev, "Error reading chip id\n"); > - return ret; > + goto disable_regulator; > } > if (val != BMI160_CHIP_ID_VAL) { > dev_err(dev, "Wrong chip id, got %x expected %x\n", > val, BMI160_CHIP_ID_VAL); > - return -ENODEV; > + ret = -ENODEV; > + goto disable_regulator; > } > > ret = bmi160_set_mode(data, BMI160_ACCEL, true); > if (ret) > - return ret; > + goto disable_regulator; > > ret = bmi160_set_mode(data, BMI160_GYRO, true); > if (ret) > - return ret; > + goto disable_accel; > > return 0; > + > +disable_accel: > + bmi160_set_mode(data, BMI160_ACCEL, false); > + > +disable_regulator: > + regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies); > + return ret; > } > > static int bmi160_data_rdy_trigger_set_state(struct iio_trigger *trig,