From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.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 B7C95392C27 for ; Mon, 15 Jun 2026 09:40:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781516456; cv=none; b=SiVJ4wXZMNNNqNvtr8RNLLeOrQQvhS9PBTuTJAYV6zYVVrsy6JVynRp6uvQNXAZAPL6l/K/94riF/x1mJzrjkv4zclZF5uUDQHvoAYScwzpQ3RXokmcPZPWVrPJ+cs4fwMdkWtEi0jJz8VuI6a0klvgLAjKR3YescTxwMsYCOcw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781516456; c=relaxed/simple; bh=uOa1yOQLFPb3K99MR8srx9ffJSwiq+AfyuufkKgrpzU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TAc7tXT9mCR724mrl6taiy01AQAwxkHwiII9KFi9X5A0VepeGo1usipu4T2oebrqecJi1MPZ4f4DfHDoJFJrfdLnI/s58phwDr/ta0EQzqwXf6SaPc9pi8/vG8LePMEYU2NrY2R6tMY5WzN4h8wsZcKuTxI5PlGL35Ssh2Ln2FA= 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=m/rggZln; arc=none smtp.client-ip=209.85.216.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m/rggZln" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-36b7b7b7a80so1854426a91.1 for ; Mon, 15 Jun 2026 02:40:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781516454; x=1782121254; 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=5EUVrIUd9a5W03H8en3F5BUxu9fsoDVhajTiBFAwOuM=; b=m/rggZlnh146bfnSu56KJRAzuHp13qV2ffjkQfLjavPEmJ7cIcpJNy7oqMPg5Vl1bZ kshNgnBYtudV6jJzs8iCug9OYdhIebh5EHAZB4VOru0FEgmEybQtEHAAoVEcig7WuH6t L8l6JgjtuQZyqD6KHqWkdsgWrUnHUzCsX7xnENZUtDz8CbiuLlezfFtFj9HDx+MqYIIf Lgyx0zpZVRuzOMdOUBT9GvDSkdVQ0U+FXKkDS50ZvZ24jT1LJr8Mq3o7P6sOODUgMj6l jUvRa3za9ibeUXkGftc4aqZ3NyFaH8Uir5l2w7gyZuxbij9GUkqZO3mAkSpIBT/dDVqf c4ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781516454; x=1782121254; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=5EUVrIUd9a5W03H8en3F5BUxu9fsoDVhajTiBFAwOuM=; b=P+QarUenR+X5y2e8iTyK/dGXqtEmadieh456nezplf3HtLRxnJBRV2f1hFbtFDWG3O /O6dY8I0tVtBftEyQ59E2Rsl5wv0WBRxU9lzxD2vy1hglX82OzkiYSmzybJ3u5TQdkgy BMekt3NU3LbHADzRDyWesLYd4oeZi6F31VHUjXeWKaEqYyOTDSmRqcfGOlEmL/kr0Cw7 vnUYgC8pbhMbXEDgpD5aoz8i4NupOtWR3RlTo48KSc/K6Fp82I3HV4deGpnn3SDOVYRg ObvMNqGRKxOgmO/Mxqg1QJQcaPBRLLP5wSUQ3b579UyROmQWZYKrpdlbbvgDPsZFl/zg 34kw== X-Forwarded-Encrypted: i=1; AFNElJ+LILhW4aLH4UsXRaKc5I0WNMXs1p9UwBZBejyqTLSAHwiOsy3PGvEMCjc+fL0s84vrJVyHO4ghgMfHCnU=@vger.kernel.org X-Gm-Message-State: AOJu0Yxu76ygmXFUJnjY8e9pY4CONcxov8LiYRw89NAkl4JAMnYwPtg1 YVa76jKtaYOAIsPfoaDnPnRXk9GTkyOqbLdSYdSnHoNJsMIxJPlE657C X-Gm-Gg: Acq92OEMtAMuIHTTbNpcKKGn41rf2xQI6HkvM98k/6EitQeC6WWGyd++wqdNN00J5pb NTaCKFRhE+Gqn+rw9FnVMXSwjqGfllrvWDi4MbxUC3oKzFr/npaE8MxzcQZRcKPp8cELA2xzlwk 76hE0nbRIzXCv5Uee2Ffzj9o00tX1fJp04c4hxTwDshEVK3W2/GS7kw4SobHjNbUq20gvY2FcM4 HOsreIR7GG37c9G0Xjz+Kg8Epe/W8suN8kDIez9bqYCwCmLCBARV/WKx/oJsXBXnBa0GA0z1GH2 dxC5XUtDZeiqDty8De1MplxwURBWpDSRluNVTbvIHhEpi+2fDNZ0qESi/c7b97czjDPePPiSVxH wg8z8FtxNka/HiA1ZgAl3op7LF3uXAUBKhMckJ4iN2iww5TCqQVmMZkXT74yTmyTz84jLlcjdxD wmdVRm6DFNEFL/uxq70VKgbs842oEBF5y3XVH6UTi8cMvWoyEtt3Z2Fg+jMQ== X-Received: by 2002:a17:90b:1dce:b0:369:7491:7b24 with SMTP id 98e67ed59e1d1-379ed8e27d2mr11149280a91.6.1781516454144; Mon, 15 Jun 2026 02:40:54 -0700 (PDT) Received: from phuc-desktop.. ([183.91.15.56]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-37a1eba8e9asm9936290a91.2.2026.06.15.02.40.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2026 02:40:52 -0700 (PDT) From: phucduc.bui@gmail.com To: Mark Brown Cc: Liam Girdwood , Jaroslav Kysela , Takashi Iwai , Shengjiu Wang , Xiubo Li , Frank Li , Fabio Estevam , Nicolin Chen , Sascha Hauer , Pengutronix Kernel Team , linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev, linuxppc-dev@lists.ozlabs.org, bui duc phuc Subject: [PATCH v2 09/11] ASoC: fsl_rpmsg: Use guard() for mutex & spin locks Date: Mon, 15 Jun 2026 16:38:22 +0700 Message-ID: <20260615093824.115751-10-phucduc.bui@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260615093824.115751-1-phucduc.bui@gmail.com> References: <20260615093824.115751-1-phucduc.bui@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 From: bui duc phuc Clean up the code using guard() for mutex & spin locks. Merely code refactoring, and no behavior change. Signed-off-by: bui duc phuc --- sound/soc/fsl/imx-pcm-rpmsg.c | 69 +++++++++++++++-------------------- 1 file changed, 30 insertions(+), 39 deletions(-) diff --git a/sound/soc/fsl/imx-pcm-rpmsg.c b/sound/soc/fsl/imx-pcm-rpmsg.c index 031e5272215d..7210393dfa5d 100644 --- a/sound/soc/fsl/imx-pcm-rpmsg.c +++ b/sound/soc/fsl/imx-pcm-rpmsg.c @@ -39,10 +39,9 @@ static int imx_rpmsg_pcm_send_message(struct rpmsg_msg *msg, struct rpmsg_device *rpdev = info->rpdev; int ret = 0; - mutex_lock(&info->msg_lock); + guard(mutex)(&info->msg_lock); if (!rpdev) { dev_err(info->dev, "rpmsg channel not ready\n"); - mutex_unlock(&info->msg_lock); return -EINVAL; } @@ -55,15 +54,12 @@ static int imx_rpmsg_pcm_send_message(struct rpmsg_msg *msg, sizeof(struct rpmsg_s_msg)); if (ret) { dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret); - mutex_unlock(&info->msg_lock); return ret; } /* No receive msg for TYPE_C command */ - if (msg->s_msg.header.type == MSG_TYPE_C) { - mutex_unlock(&info->msg_lock); + if (msg->s_msg.header.type == MSG_TYPE_C) return 0; - } /* wait response from rpmsg */ ret = wait_for_completion_timeout(&info->cmd_complete, @@ -71,7 +67,6 @@ static int imx_rpmsg_pcm_send_message(struct rpmsg_msg *msg, if (!ret) { dev_err(&rpdev->dev, "rpmsg_send cmd %d timeout!\n", msg->s_msg.header.cmd); - mutex_unlock(&info->msg_lock); return -ETIMEDOUT; } @@ -100,8 +95,6 @@ static int imx_rpmsg_pcm_send_message(struct rpmsg_msg *msg, dev_dbg(&rpdev->dev, "cmd:%d, resp %d\n", msg->s_msg.header.cmd, info->r_msg.param.resp); - mutex_unlock(&info->msg_lock); - return 0; } @@ -109,14 +102,13 @@ static int imx_rpmsg_insert_workqueue(struct snd_pcm_substream *substream, struct rpmsg_msg *msg, struct rpmsg_info *info) { - unsigned long flags; int ret = 0; /* * Queue the work to workqueue. * If the queue is full, drop the message. */ - spin_lock_irqsave(&info->wq_lock, flags); + guard(spinlock_irqsave)(&info->wq_lock); if (info->work_write_index != info->work_read_index) { int index = info->work_write_index; @@ -130,7 +122,6 @@ static int imx_rpmsg_insert_workqueue(struct snd_pcm_substream *substream, info->msg_drop_count[substream->stream]++; ret = -EPIPE; } - spin_unlock_irqrestore(&info->wq_lock, flags); return ret; } @@ -523,7 +514,6 @@ static int imx_rpmsg_pcm_ack(struct snd_soc_component *component, snd_pcm_sframes_t avail; struct timer_list *timer; struct rpmsg_msg *msg; - unsigned long flags; int buffer_tail = 0; int written_num; @@ -553,11 +543,11 @@ static int imx_rpmsg_pcm_ack(struct snd_soc_component *component, msg->s_msg.param.buffer_tail = buffer_tail; /* The notification message is updated to latest */ - spin_lock_irqsave(&info->lock[substream->stream], flags); - memcpy(&info->notify[substream->stream], msg, - sizeof(struct rpmsg_s_msg)); - info->notify_updated[substream->stream] = true; - spin_unlock_irqrestore(&info->lock[substream->stream], flags); + scoped_guard(spinlock_irqsave, &info->lock[substream->stream]) { + memcpy(&info->notify[substream->stream], msg, + sizeof(struct rpmsg_s_msg)); + info->notify_updated[substream->stream] = true; + } if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) avail = snd_pcm_playback_hw_avail(runtime); @@ -640,7 +630,7 @@ static void imx_rpmsg_pcm_work(struct work_struct *work) bool is_notification = false; struct rpmsg_info *info; struct rpmsg_msg msg; - unsigned long flags; + bool updated; work_of_rpmsg = container_of(work, struct work_of_rpmsg, work); info = work_of_rpmsg->info; @@ -651,25 +641,26 @@ static void imx_rpmsg_pcm_work(struct work_struct *work) * enough data in M core side, need to let M core know * data is updated immediately. */ - spin_lock_irqsave(&info->lock[TX], flags); - if (info->notify_updated[TX]) { - memcpy(&msg, &info->notify[TX], sizeof(struct rpmsg_s_msg)); - info->notify_updated[TX] = false; - spin_unlock_irqrestore(&info->lock[TX], flags); - info->send_message(&msg, info); - } else { - spin_unlock_irqrestore(&info->lock[TX], flags); + scoped_guard(spinlock_irqsave, &info->lock[TX]) { + updated = info->notify_updated[TX]; + if (updated) { + memcpy(&msg, &info->notify[TX], sizeof(struct rpmsg_s_msg)); + info->notify_updated[TX] = false; + } } - - spin_lock_irqsave(&info->lock[RX], flags); - if (info->notify_updated[RX]) { - memcpy(&msg, &info->notify[RX], sizeof(struct rpmsg_s_msg)); - info->notify_updated[RX] = false; - spin_unlock_irqrestore(&info->lock[RX], flags); + if (updated) info->send_message(&msg, info); - } else { - spin_unlock_irqrestore(&info->lock[RX], flags); + + scoped_guard(spinlock_irqsave, &info->lock[RX]) { + updated = info->notify_updated[RX]; + if (updated) { + memcpy(&msg, &info->notify[RX], sizeof(struct rpmsg_s_msg)); + info->notify_updated[RX] = false; + } } + if (updated) + info->send_message(&msg, info); + /* Skip the notification message for it has been processed above */ if (work_of_rpmsg->msg.s_msg.header.type == MSG_TYPE_C && @@ -681,10 +672,10 @@ static void imx_rpmsg_pcm_work(struct work_struct *work) info->send_message(&work_of_rpmsg->msg, info); /* update read index */ - spin_lock_irqsave(&info->wq_lock, flags); - info->work_read_index++; - info->work_read_index %= WORK_MAX_NUM; - spin_unlock_irqrestore(&info->wq_lock, flags); + scoped_guard(spinlock_irqsave, &info->wq_lock) { + info->work_read_index++; + info->work_read_index %= WORK_MAX_NUM; + } } static int imx_rpmsg_pcm_probe(struct platform_device *pdev) -- 2.43.0