Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp58833lqp; Sun, 9 Jun 2024 16:38:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWxi1sAy1j41T/7ZUjO3bTgezzjTXF7Qa7L0I7jSxiqeft5Zl3YWRjPTEmMGjcBmaowe22EuVLSY4diVDGU5m5gDXeVPGiquMNeMq2OtQ== X-Google-Smtp-Source: AGHT+IFrPYo2E+UwmChMVdpV8neWu+aVLjvd0GVpMseIW3HDGFyOzPpUS6HF3WMFKaEd5JbwVSsG X-Received: by 2002:a05:6a20:da86:b0:1b6:98ba:8df5 with SMTP id adf61e73a8af0-1b698ba8ef5mr2071779637.21.1717976330437; Sun, 09 Jun 2024 16:38:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717976330; cv=pass; d=google.com; s=arc-20160816; b=VTKyln82sKtpv4eN8Devo4mznS0gZV6KlPCdPbs433k9We3UTV8WeDSNL7dB0JCc4u kkwX8jWpO7R9Xh9VB6HLHMfzak0ZeCeThf7asH18MxR/vJRYQxinl+3WBU5gwZ5ywUMU rjgKnXhTIiGFU3/JhWqsxTgxypY17U2EO9d9+ZKd3qFnXyq7GXi8DwBtBnhl5nQ6iwao KZXVlx35YOnPa/6t9za90Z034G3ZditU1Jkjv8AcRYWQ1QGluVHeROvtBAotTsGqx1gY BHzz4chCjYfNPf3cLlgjTxUTrz3XEgxa4yqZOaIrxORafnSRLNWS71RYOo5slF4Gzi/a fyCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=qriIk15uECH849+rrPmyWW+JdSulOHZnSzKJ2HLoQPc=; fh=ax1xxuQY9STLvn2RyimHv7wuEWFwKx1ENoRpUj3vLnc=; b=MZqiaHhym20FlzCcqyTss4MiwzA8fpZ/xJzsI77qqRxWeMvKTjrIdAtDx2ue/g3UHl XEd9xNtmHmxJPN0M7DkmN/ee1aEbb8KVhat+RUlnx8XZ/Z//AdNMvSq7slCtbMZyRjSj Ui1WcydfPmxpPnIVL+33NYD+EWWalfDept7UVP9g778fR2xABvveKZx9oXVOBSEjx0nu 2Mq8L2ciQ+pU5GrzJmavVtc8FuJjlGbsy9yJzy2ds1LHp9ZHri/5i8QR/xubSOgMZJpJ IGb/07yNqkJ13qLAOolot6Wv2a/tv9egQ25l4YPG7zlYv4f5XSceT1UePlR8QhBF6Gx3 3TQA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FdJHhy5q; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-207540-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207540-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d2e1a72fcca58-704123d729fsi4020258b3a.61.2024.06.09.16.38.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 16:38:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-207540-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FdJHhy5q; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-207540-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207540-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0A21E2812E3 for ; Sun, 9 Jun 2024 23:38:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6788F558A5; Sun, 9 Jun 2024 23:38:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FdJHhy5q" Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07C0045BEF; Sun, 9 Jun 2024 23:38:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717976314; cv=none; b=C6haL08SYP5l5gK+pJk2wALgh6bzSGB7GavGb3Wav4qSMZurVwylYzVPBUKwq81EA4Qr5Mxm+QK/2uypRivTU4sMVvRHI5tg2pDipbVVj7nnfGX67tT+kymMm3J0YB4Y4DZDXalbwMc/a71Zr5roiuPsRT7ZCuI5cIAqngTsNac= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717976314; c=relaxed/simple; bh=/HIExraWSYrCMoCk7nOoIvhEXeD3HpJ2VyeOWxhE7ww=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HlJ3NL92ADVbihr12xchdLOR+UiRYxYRYOMsUcjhqnj/p2uOYykkciPxH2Lq4yAMKmUdL4OkIxSqaz9PtSe33E5PFE9WmE4fU+xulQaTK8h034claPL5/5mCI4+mJsf+MPaIHXr7kYmKHJRk0fW4o8cRWMObZwdMo+RUyNabkwU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FdJHhy5q; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a6ef8bf500dso174193466b.0; Sun, 09 Jun 2024 16:38:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717976311; x=1718581111; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qriIk15uECH849+rrPmyWW+JdSulOHZnSzKJ2HLoQPc=; b=FdJHhy5qZz0dYz9CeDIv94IZ1PwKHU8v6U0j6aMRWhZYDRLc/zk2l0hyZyk3BnlzGR 2i6numns0GStILgXJisp6kLBSnDM8LbxIOS+7MKB5sX3lFF1i1mw9G7xt0MQrX4hJ1/Q Mci33uNwcwG9ABTo3538A1SUqSsvylDb+/hREv5dvcfeDMxQ+vYPAiGX9cmUm0J1lGHW PDWIOqo855cnu4qYl4Vcx3rsPyh1iki+iEeXLAWwxDBzDszWC1UHba6YrITXsv8FA7Xv D8pnR127+gojB6hlpMH7y6pmUwl6sWLLgRXd6MnyP6WMlx2C9oqnWFIz90+1B/aCFhic 4fRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717976311; x=1718581111; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qriIk15uECH849+rrPmyWW+JdSulOHZnSzKJ2HLoQPc=; b=lBZPFLJoWwsLsAOazsm9BAhOIP5vtx6oHsThPIQhiwwxdwAcbEJtLegqHNypuhqfOn 2/b2AsOcZ7efYPZsERS3jWbEEAYcz6urNVM7oFZLJgjjKoCY7e4tE6YNmPj+EjNjA3By A2xQtryXtWHfqHYggVTs75B20BJdgBpUwLYbbRSChVg+yCpRVhseWfqlM1+oeOINVyQQ N2fCZf/1wqqo/1I0rW3uUmjVcwZEurBBU5rE/sF9out22Y1aBgqmQYplaxZRzd/BE5pK usMJXZRY9WyClk7eCwb36JOnQBOCRu+rCUHCeeG8gTrJBY1x0zQneTDrf9bQ2nKuIfZm zV1Q== X-Forwarded-Encrypted: i=1; AJvYcCVRSosD+QhwEHeGCYAQSYY3/F+dBvmmGhqDWeYHe/cUM60Uj4cDJoX7V1ozshK0WXgs1Y9ndSwWkJRDJlmII2raPgDh0u/DsFoGgkvKz5CtnQW5JfewflTcLqF9x9aI5qlR/OvB2jur X-Gm-Message-State: AOJu0YwIrY6hfM2oD10JXXBDEnS6R8ocNPWaEsGF3F3M3uv+tq7MaVan YPCDzhZgxSTO7aB1Cgkc6W/u3oYrtC9DO+lSjUQgtdd5EMeTzI/i X-Received: by 2002:a17:906:2c16:b0:a68:a800:5f7e with SMTP id a640c23a62f3a-a6cd561f12cmr526136166b.10.1717976311357; Sun, 09 Jun 2024 16:38:31 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:635a:738f:880f:9ea5]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6f20bb1abesm46063366b.172.2024.06.09.16.38.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 16:38:30 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org Cc: dpfrey@gmail.com, himanshujha199640@gmail.com, lars@metafoo.de, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, mike.looijmans@topic.nl, vassilisamir@gmail.com Subject: [PATCH v3 01/15] iio: chemical: bme680: Fix read/write ops to device by adding mutexes Date: Mon, 10 Jun 2024 01:38:12 +0200 Message-Id: <20240609233826.330516-2-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240609233826.330516-1-vassilisamir@gmail.com> References: <20240609233826.330516-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add mutexes in the {read/write}_raw() functions of the device to guard the read/write of data from/to the device. This is necessary because for any operation other than temperature, multiple reads need to take place from the device. Even though regmap has a locking by itself, it won't protect us from multiple applications trying to read at the same time temperature and pressure since the pressure reading includes an internal temperature reading and there is nothing to ensure that this temperature+pressure reading will happen sequentially without any other operation interfering in the meantime. Fixes: 1b3bd8592780 ("iio: chemical: Add support for Bosch BME680 sensor") Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680_core.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c index 500f56834b01..a6bf689833da 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -10,6 +10,7 @@ */ #include #include +#include #include #include #include @@ -52,6 +53,7 @@ struct bme680_calib { struct bme680_data { struct regmap *regmap; struct bme680_calib bme680; + struct mutex lock; /* Protect multiple serial R/W ops to device. */ u8 oversampling_temp; u8 oversampling_press; u8 oversampling_humid; @@ -827,6 +829,8 @@ static int bme680_read_raw(struct iio_dev *indio_dev, { struct bme680_data *data = iio_priv(indio_dev); + guard(mutex)(&data->lock); + switch (mask) { case IIO_CHAN_INFO_PROCESSED: switch (chan->type) { @@ -871,6 +875,8 @@ static int bme680_write_raw(struct iio_dev *indio_dev, { struct bme680_data *data = iio_priv(indio_dev); + guard(mutex)(&data->lock); + if (val2 != 0) return -EINVAL; @@ -967,6 +973,7 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap, name = bme680_match_acpi_device(dev); data = iio_priv(indio_dev); + mutex_init(&data->lock); dev_set_drvdata(dev, indio_dev); data->regmap = regmap; indio_dev->name = name; -- 2.25.1