From: Ricardo Ribalda <ribalda@chromium.org>
To: Andy Walls <awalls@md.metrocast.net>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Sean Young <sean@mess.org>, Jarod Wilson <jarod@redhat.com>
Cc: Hans Verkuil <hverkuil-cisco@xs4all.nl>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
Ricardo Ribalda <ribalda@chromium.org>
Subject: [PATCH 4/5] media: go7007: Refactor Adlink PCI-MPG24 i2c mutex
Date: Mon, 06 May 2024 21:10:29 +0000 [thread overview]
Message-ID: <20240506-cocci-locks-v1-4-a67952fe5d19@chromium.org> (raw)
In-Reply-To: <20240506-cocci-locks-v1-0-a67952fe5d19@chromium.org>
Move the lock/unlock to its own function. It makes the code cleaner and
cocci happier.
Fix the following cocci warning:
drivers/media/usb/go7007/go7007-i2c.c:125:1-7: preceding lock on line 61
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
drivers/media/usb/go7007/go7007-i2c.c | 30 +++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)
diff --git a/drivers/media/usb/go7007/go7007-i2c.c b/drivers/media/usb/go7007/go7007-i2c.c
index 2880370e45c8..f6ce28a4a768 100644
--- a/drivers/media/usb/go7007/go7007-i2c.c
+++ b/drivers/media/usb/go7007/go7007-i2c.c
@@ -33,7 +33,21 @@
/* There is only one I2C port on the TW2804 that feeds all four GO7007 VIPs
* on the Adlink PCI-MPG24, so access is shared between all of them. */
-static DEFINE_MUTEX(adlink_mpg24_i2c_lock);
+static DEFINE_MUTEX(adlink_mpg24_i2c_mutex);
+
+static inline void adlink_mpg24_i2c_lock(struct go7007 *go)
+{
+ /* Bridge the I2C port on this GO7007 to the shared bus */
+ mutex_lock(&adlink_mpg24_i2c_mutex);
+ go7007_write_addr(go, 0x3c82, 0x0020);
+}
+
+static inline void adlink_mpg24_i2c_unlock(struct go7007 *go)
+{
+ /* Isolate the I2C port on this GO7007 from the shared bus */
+ go7007_write_addr(go, 0x3c82, 0x0000);
+ mutex_unlock(&adlink_mpg24_i2c_mutex);
+}
static int go7007_i2c_xfer(struct go7007 *go, u16 addr, int read,
u16 command, int flags, u8 *data)
@@ -56,11 +70,8 @@ static int go7007_i2c_xfer(struct go7007 *go, u16 addr, int read,
mutex_lock(&go->hw_lock);
- if (go->board_id == GO7007_BOARDID_ADLINK_MPG24) {
- /* Bridge the I2C port on this GO7007 to the shared bus */
- mutex_lock(&adlink_mpg24_i2c_lock);
- go7007_write_addr(go, 0x3c82, 0x0020);
- }
+ if (go->board_id == GO7007_BOARDID_ADLINK_MPG24)
+ adlink_mpg24_i2c_lock(go);
/* Wait for I2C adapter to be ready */
for (i = 0; i < 10; ++i) {
@@ -116,11 +127,8 @@ static int go7007_i2c_xfer(struct go7007 *go, u16 addr, int read,
ret = 0;
i2c_done:
- if (go->board_id == GO7007_BOARDID_ADLINK_MPG24) {
- /* Isolate the I2C port on this GO7007 from the shared bus */
- go7007_write_addr(go, 0x3c82, 0x0000);
- mutex_unlock(&adlink_mpg24_i2c_lock);
- }
+ if (go->board_id == GO7007_BOARDID_ADLINK_MPG24)
+ adlink_mpg24_i2c_unlock(go);
mutex_unlock(&go->hw_lock);
return ret;
}
--
2.45.0.rc1.225.g2a3ae87e7f-goog
next prev parent reply other threads:[~2024-05-06 21:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-06 21:10 [PATCH 0/5] media: Fix some cocci locks warnings Ricardo Ribalda
2024-05-06 21:10 ` [PATCH 1/5] media: ivtv: Factor out schedule functions Ricardo Ribalda
2024-05-06 21:10 ` [PATCH 2/5] media: imon: Fix race getting ictx->lock Ricardo Ribalda
2024-05-06 21:10 ` [PATCH 3/5] media: dvb-frontends/stv090x: Refactor tuner_i2c_lock Ricardo Ribalda
2024-05-06 21:10 ` Ricardo Ribalda [this message]
2024-05-06 21:10 ` [PATCH 5/5] media: drivers/media/dvb-core: Refactor dvb_frontend_open Ricardo Ribalda
2024-05-30 13:19 ` Hans Verkuil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240506-cocci-locks-v1-4-a67952fe5d19@chromium.org \
--to=ribalda@chromium.org \
--cc=awalls@md.metrocast.net \
--cc=hverkuil-cisco@xs4all.nl \
--cc=jarod@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=sean@mess.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).