Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4755365iob; Mon, 9 May 2022 00:22:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAGuIcKAQF96+d6B2Fjxzev+YJFIq9BCBbgTZ+Nxj1/irKpiAafERGGMSKiGj7biOVRBD1 X-Received: by 2002:a63:7d0:0:b0:3c6:77a1:10a4 with SMTP id 199-20020a6307d0000000b003c677a110a4mr7752367pgh.587.1652080940022; Mon, 09 May 2022 00:22:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652080940; cv=none; d=google.com; s=arc-20160816; b=u9PSvnRkP1bE77fEEg/sWl/FpdJ63HiAmNeXhBdcVVpnegwkz25rhYJBz/mMTXFRvU huohnjyvj6oZlIqqgbZc/XqRJzGSpkgAtWX08+CfkXZ5FnyKJldSU37vavoiw6NAGxJS oXWshWy2bttwrrXeW/xnJA5XB3FBOWUQpzx76PDUoCK6mjq2pYNKh1ytTRdb1N+gaX8M VVat+23VkgHTE1gqGZ0dHugQwbMU0L5gD+UoHlXnDEBdXcmMACVJk0NcMjUJpd1LeZbX INQVS05m5UbFAkF4YLHvW0uZZieOji9ld85AYlG9vYPs8pZP2hFI49yCGLCCwGEF1ph8 rCdQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PfOlHhNj7v7otqu+/TNtKiIZ978/hfESXVoyuL9ccX8=; b=VgYk0XhYmrZySrKA7v9kPfP/qDSr6JHX1Q8WruCAZFUmL4AT4P66nMopZjq1+k9p0e bysTbWlAKNLDws7qeR+v+7bN9FFhTl+aSE/LwWQL+e2REXME7nd2mnDLOfI4QtS52CJm HOTpAzjs9ACDD9YznBXv3YVrQBgcxAsLdWOZSWT+OO31RtylRee6dQfFbVASVBgdeFGH ap7DhualouNOltySNOcYIM5fC9adkPCpT1LmNPZhmHqpK95ioPoFJQI4G7dpdu3oKj56 0EbRl37lgU5lfcXJ3og40BIo4/8sB3sklQQOAK7J6m/ELGF8dCDN1HjsHDqXYEnJmFb2 raZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=S42KLcMM; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id k5-20020a654645000000b003c6c6dfc3e3si2858364pgr.143.2022.05.09.00.22.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 00:22:20 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=S42KLcMM; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6F7A9E0FD; Mon, 9 May 2022 00:20:18 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356169AbiEDRE4 (ORCPT + 99 others); Wed, 4 May 2022 13:04:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354585AbiEDQ6x (ORCPT ); Wed, 4 May 2022 12:58:53 -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 B3BA3193EC; Wed, 4 May 2022 09:50:38 -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 433EE6179D; Wed, 4 May 2022 16:50:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8CE7DC385A5; Wed, 4 May 2022 16:50:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651683037; bh=3tCD9UPGGLCqsAMO+Vo9sno0Rmur0LR0rPnUEVYNJ6A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S42KLcMML8dvqJhjAgM+/S/BVbESIhElHwD0aoY9E4zDFf42ubf3hoaSdaI0e+fZW 9uS0yRuUtsZeZQuhEyNyN9BN0wIVtd58++L5rQ8360uVd56ISNhv/g9Ej019GcQmtc oVorHjzTxFNyX4SUIOvEGJTnc83lIalMKu2lrWLU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Shevchenko , Tong Zhang , Jonathan Cameron , Sasha Levin Subject: [PATCH 5.10 041/129] iio:imu:bmi160: disable regulator in error path Date: Wed, 4 May 2022 18:43:53 +0200 Message-Id: <20220504153024.435636515@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504153021.299025455@linuxfoundation.org> References: <20220504153021.299025455@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Tong Zhang [ Upstream commit d926054d5565d3cfa2c7c3f7a48e79bcc10453ed ] 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 Link: https://lore.kernel.org/r/20220327154005.806049-1-ztong0001@gmail.com Signed-off-by: Jonathan Cameron Signed-off-by: Sasha Levin --- 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 82f03a4dc47a..5fd61889f593 100644 --- a/drivers/iio/imu/bmi160/bmi160_core.c +++ b/drivers/iio/imu/bmi160/bmi160_core.c @@ -731,7 +731,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); @@ -742,29 +742,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, -- 2.35.1