From patchwork Mon Feb 7 14:38:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 12737308 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AA39C433EF for ; Mon, 7 Feb 2022 14:57:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236679AbiBGO46 (ORCPT ); Mon, 7 Feb 2022 09:56:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237317AbiBGOiq (ORCPT ); Mon, 7 Feb 2022 09:38:46 -0500 Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [IPv6:2001:4b98:dc4:8::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6F78C0401C2 for ; Mon, 7 Feb 2022 06:38:44 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 6D58010000A; Mon, 7 Feb 2022 14:38:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1644244723; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TawdqjX7BEkznrUMkUPTanTqZyIkwauouY0To3CdU2s=; b=IRk3yVLSOWB7iFl68cInmVeAgHQZWL+aGqe5pyYjG7cDkzere+vQZ8J0S/ywGLlXyQB0IW BF5cNvDPL481uIprrXrrB5UdpciA/78kPW3JD3FTJOHJ/8m1K2GRzPER3KqAAZ1HtpwgFh 4e3BS/HFigL2IrFSuZrK103ed1aQfivVsI1Gtis6C9sahlhllM9DU7KdwrwgRl2aVRA83+ HUPJHR3j25Mem+SIF1eP72W5fYWS/usv5JH8TXTdBHTnST2lVjao59RPEGxeGOA9nLNPIK wuGRjO7NSZRsqF1Act42lO7sRVkdDVJ0UQ74VvRNwpbahGUjeXZ7lhmwaCMZXw== From: Miquel Raynal To: linux-iio@vger.kernel.org, Jonathan Cameron , Lars-Peter Clausen Cc: Thomas Petazzoni , Alexandru Ardelean , Miquel Raynal , Song Qiang Subject: [PATCH v3 02/13] iio: magnetometer: rm3100: Stop abusing the ->currentmode Date: Mon, 7 Feb 2022 15:38:29 +0100 Message-Id: <20220207143840.707510-3-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220207143840.707510-1-miquel.raynal@bootlin.com> References: <20220207143840.707510-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This is an internal variable for the core, here it is set to a "default" value by the driver in order to later be able to perform checks against it. None of this is needed because this check actually cares about the buffers being enabled or not. So it is an unproper side-channel access to the information "are the buffers enabled?", returned officially by the iio_buffer_enabled() helper. Use this helper instead. Cc: Song Qiang Signed-off-by: Miquel Raynal --- drivers/iio/magnetometer/rm3100-core.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/drivers/iio/magnetometer/rm3100-core.c b/drivers/iio/magnetometer/rm3100-core.c index 13914273c999..be0057f82218 100644 --- a/drivers/iio/magnetometer/rm3100-core.c +++ b/drivers/iio/magnetometer/rm3100-core.c @@ -141,18 +141,10 @@ static irqreturn_t rm3100_irq_handler(int irq, void *d) struct iio_dev *indio_dev = d; struct rm3100_data *data = iio_priv(indio_dev); - switch (indio_dev->currentmode) { - case INDIO_DIRECT_MODE: + if (!iio_buffer_enabled(indio_dev)) complete(&data->measuring_done); - break; - case INDIO_BUFFER_TRIGGERED: + else iio_trigger_poll(data->drdy_trig); - break; - default: - dev_err(indio_dev->dev.parent, - "device mode out of control, current mode: %d", - indio_dev->currentmode); - } return IRQ_WAKE_THREAD; } @@ -377,7 +369,7 @@ static int rm3100_set_samp_freq(struct iio_dev *indio_dev, int val, int val2) goto unlock_return; } - if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { + if (iio_buffer_enabled(indio_dev)) { /* Writing TMRC registers requires CMM reset. */ ret = regmap_write(regmap, RM3100_REG_CMM, 0); if (ret < 0) @@ -553,7 +545,6 @@ int rm3100_common_probe(struct device *dev, struct regmap *regmap, int irq) indio_dev->channels = rm3100_channels; indio_dev->num_channels = ARRAY_SIZE(rm3100_channels); indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_TRIGGERED; - indio_dev->currentmode = INDIO_DIRECT_MODE; if (!irq) data->use_interrupt = false;