Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2016556pxp; Fri, 18 Mar 2022 00:46:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzI9ZD6vCK1EPCYxARZGPy5El9uIF+B9nXW+4JdnYQYYcobI3oiUwFb9+7QFCqenvt8zj/K X-Received: by 2002:a17:90a:1f4d:b0:1bb:a657:ace5 with SMTP id y13-20020a17090a1f4d00b001bba657ace5mr20042261pjy.39.1647589570234; Fri, 18 Mar 2022 00:46:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647589570; cv=none; d=google.com; s=arc-20160816; b=fff2bfMASoq9weUtbcMmed7mVaXV4tUa8Nu8G+YWP7zyJLFejfJnP9rtOBXS34RUDN 6EX7DTX6KjtjbS/XHfV4aTEQGnRGOyfsbPZ6Zpp/FQfHuJYwKpuUJTWDiOXCkVQ5h4Jm 8KHY9u0HUPC6aXGybkWFFzBrMU+pYTj07JKZ+FNe3AHfqhqzZUnJUWmDB7X0an1yC+Vz Sy3+U8iE6dcTPE3Wx7RbH8KhVFhh3HlS1qbHSc2OGAzc5QQAEsHBbYVbeuuGSus1mR5y nS7NidGo2xqi1HU4D1xe8oHyJEsJmKGju/oJCF/RDnTYB9oao1Ua5lbHeSqOposUVsF5 h2Kg== 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:to:from:dkim-signature; bh=oisiYBwgNe77NYhtZp8TE9csHemqrDrXVik9thaoeSs=; b=PM7dd0GZ6hzdl+JWL4ITUIs3d4dDKzTzH84pCqJWGpbWMmjVWtL1pw3jVD8J/W0KhA EOUj4dQN7CqFl7wygbpfkrZi/k9cKzb4/c+ZiK4rnlP1MoPwM4P0akTUBw7d4S2YnwLE wU5Rup1hcwtZUZ+vcoO0FXvI3CTV2w+cM/QWzUEdafBmc9//k2pB+GWQ5Q7hn6FMUXM0 E49bVDgzfxMVcJ/V5AtNBXyg26kPGMTArLDkHMqHdkFKZgHCAzxzEX0he6JBxsloSo7/ i33Uq5Qr50Qw5ZCyQB2ucaz+tD5RBO0RJt4XwayHVBB8dfCL3+EeuPPW4qFVpWkJPVPf sbiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lDS9sTbA; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l13-20020a654c4d000000b003816043ee73si4188935pgr.104.2022.03.18.00.45.57; Fri, 18 Mar 2022 00:46:10 -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=@gmail.com header.s=20210112 header.b=lDS9sTbA; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232937AbiCRHKg (ORCPT + 99 others); Fri, 18 Mar 2022 03:10:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230269AbiCRHKe (ORCPT ); Fri, 18 Mar 2022 03:10:34 -0400 Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FC35222A6; Fri, 18 Mar 2022 00:09:16 -0700 (PDT) Received: by mail-qk1-x72b.google.com with SMTP id z66so6150867qke.10; Fri, 18 Mar 2022 00:09:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=oisiYBwgNe77NYhtZp8TE9csHemqrDrXVik9thaoeSs=; b=lDS9sTbAi2rvVxc/T+ptjJaKEJkFmYlaYuJhtpmrMcYNoMKRrPyUTOT+wXHXYriTix mg1LAXbGYr6nYlP34ER5Cg3KdkbqdCnSnSFPEKOXIbcPhWJl9sANrptHvR/Oslcn/0yr 41qB1nc7EWl900TWKkaceLmCGBl3Gjl22EpJLL4mlqfWuHzli8ZutCFFoZlm5D0DTKxR VdzGFdntFWZ+uNn0Db0pysbK/nDD/zosDIM+mlFvYpbwfHzue/Du0cj6gHA/dyPN8/Qq Sw4t6UElOQDn7aW4yoqKq7Al5qrk8DXgkRMwuryJB9iSJrGhj2MvOQEdC5yzAMA9zHZQ ETQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=oisiYBwgNe77NYhtZp8TE9csHemqrDrXVik9thaoeSs=; b=CHwqb9+Y0h/b1cj0qNX2PDY4IfMsCP7BS0D2vP0Ila2MzwbZdf3Jge+x9hqnxyA3C2 TYydnRAFYd0R8Um40UGgGf1/oJl61FqqgO6Njmts5/F0RFe0FGbBkBxbveSAreFxp69g GuZLvkN2qnCe7YEd4FmAOmBCOsrzUvLQ+7YWGcYuSvnohxo7XNa7DReAFjtB8n/oG4Gw hHI/R0gv9mlZBi63m5C53NbUu04fZR3TxvI/WBWTjhhaX3W5CxFev2TvDfiJVICLC5Tc dmQrkElu2J3kjDzVyLOHBvx1Xn0qqzuepOSkNqr4pBj2SuDxcEZSEPbgTrNcCCNk5idK 254g== X-Gm-Message-State: AOAM5302DLifb1EXfRfytcTKnhz18cg4tN2uwNlpo7kZ6O1agaS/P31G czB22hN9z/b8bmIrx4eDB6s= X-Received: by 2002:a05:620a:4493:b0:67b:1ead:13b8 with SMTP id x19-20020a05620a449300b0067b1ead13b8mr5011387qkp.716.1647587355584; Fri, 18 Mar 2022 00:09:15 -0700 (PDT) Received: from tong-desktop.local (99-105-211-126.lightspeed.sntcca.sbcglobal.net. [99.105.211.126]) by smtp.googlemail.com with ESMTPSA id d6-20020ac85d86000000b002e1e20444b6sm5248731qtx.57.2022.03.18.00.09.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Mar 2022 00:09:15 -0700 (PDT) From: Tong Zhang To: Jonathan Cameron , Lars-Peter Clausen , Tong Zhang , Linus Walleij , Alexandru Ardelean , Andy Shevchenko , Jonathan Albrieux , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] iio:imu:bmi160: disable regulator in error path Date: Fri, 18 Mar 2022 00:09:00 -0700 Message-Id: <20220318070900.2499370-1-ztong0001@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,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 regulator should be disabled in error path as mentioned in _regulator_put() [ 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") Signed-off-by: Tong Zhang --- drivers/iio/imu/bmi160/bmi160_core.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c index 824b5124a5f5..f12446edb5ce 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,34 @@ 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_regulator; return 0; + +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.25.1