[PATCH 12/12] ASoC: qcom: q6asm: Use guard() for spin locks

Srinivas Kandagatla posted 12 patches 3 months, 3 weeks ago
[PATCH 12/12] ASoC: qcom: q6asm: Use guard() for spin locks
Posted by Srinivas Kandagatla 3 months, 3 weeks ago
Clean up the code using guard() for spin locks.

No functional changes, just cleanup.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
---
 sound/soc/qcom/qdsp6/q6asm.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)

diff --git a/sound/soc/qcom/qdsp6/q6asm.c b/sound/soc/qcom/qdsp6/q6asm.c
index 366fe8a8387f..7c9d1494e8b9 100644
--- a/sound/soc/qcom/qdsp6/q6asm.c
+++ b/sound/soc/qcom/qdsp6/q6asm.c
@@ -569,9 +569,8 @@ static struct audio_client *q6asm_get_audio_client(struct q6asm *a,
 						   int session_id)
 {
 	struct audio_client *ac = NULL;
-	unsigned long flags;
 
-	spin_lock_irqsave(&a->slock, flags);
+	guard(spinlock_irqsave)(&a->slock);
 	if ((session_id <= 0) || (session_id > MAX_SESSIONS)) {
 		dev_err(a->dev, "invalid session: %d\n", session_id);
 		goto err;
@@ -586,7 +585,6 @@ static struct audio_client *q6asm_get_audio_client(struct q6asm *a,
 	ac = a->session[session_id];
 	kref_get(&ac->refcount);
 err:
-	spin_unlock_irqrestore(&a->slock, flags);
 	return ac;
 }
 
@@ -666,15 +664,13 @@ static int32_t q6asm_stream_callback(struct apr_device *adev,
 		client_event = ASM_CLIENT_EVENT_DATA_WRITE_DONE;
 		if (ac->io_mode & ASM_SYNC_IO_MODE) {
 			phys_addr_t phys;
-			unsigned long flags;
 			int token = hdr->token & ASM_WRITE_TOKEN_MASK;
 
-			spin_lock_irqsave(&ac->lock, flags);
+			guard(spinlock_irqsave)(&ac->lock);
 
 			port =  &ac->port[SNDRV_PCM_STREAM_PLAYBACK];
 
 			if (!port->buf) {
-				spin_unlock_irqrestore(&ac->lock, flags);
 				ret = 0;
 				goto done;
 			}
@@ -685,24 +681,21 @@ static int32_t q6asm_stream_callback(struct apr_device *adev,
 			    upper_32_bits(phys) != result->status) {
 				dev_err(ac->dev, "Expected addr %pa\n",
 					&port->buf[token].phys);
-				spin_unlock_irqrestore(&ac->lock, flags);
 				ret = -EINVAL;
 				goto done;
 			}
-			spin_unlock_irqrestore(&ac->lock, flags);
+			atomic_set(&port->hw_ptr, token + 1);
 		}
 		break;
 	case ASM_DATA_EVENT_READ_DONE_V2:
 		client_event = ASM_CLIENT_EVENT_DATA_READ_DONE;
 		if (ac->io_mode & ASM_SYNC_IO_MODE) {
 			struct asm_data_cmd_read_v2_done *done = data->payload;
-			unsigned long flags;
 			phys_addr_t phys;
 
-			spin_lock_irqsave(&ac->lock, flags);
+			guard(spinlock_irqsave)(&ac->lock);
 			port =  &ac->port[SNDRV_PCM_STREAM_CAPTURE];
 			if (!port->buf) {
-				spin_unlock_irqrestore(&ac->lock, flags);
 				ret = 0;
 				goto done;
 			}
@@ -715,11 +708,9 @@ static int32_t q6asm_stream_callback(struct apr_device *adev,
 					&port->buf[hdr->token].phys,
 					done->buf_addr_lsw,
 					done->buf_addr_msw);
-				spin_unlock_irqrestore(&ac->lock, flags);
 				ret = -EINVAL;
 				goto done;
 			}
-			spin_unlock_irqrestore(&ac->lock, flags);
 		}
 
 		break;
@@ -1544,14 +1535,12 @@ EXPORT_SYMBOL_GPL(q6asm_write_async);
 static void q6asm_reset_buf_state(struct audio_client *ac)
 {
 	struct audio_port_data *port;
-	unsigned long flags;
 
-	spin_lock_irqsave(&ac->lock, flags);
+	guard(spinlock_irqsave)(&ac->lock);
 	port = &ac->port[SNDRV_PCM_STREAM_PLAYBACK];
 	port->dsp_buf = 0;
 	port = &ac->port[SNDRV_PCM_STREAM_CAPTURE];
 	port->dsp_buf = 0;
-	spin_unlock_irqrestore(&ac->lock, flags);
 }
 
 static int __q6asm_cmd(struct audio_client *ac, uint32_t stream_id, int cmd,
-- 
2.51.0
Re: [PATCH 12/12] ASoC: qcom: q6asm: Use guard() for spin locks
Posted by kernel test robot 3 months, 3 weeks ago
Hi Srinivas,

kernel test robot noticed the following build errors:

[auto build test ERROR on broonie-sound/for-next]
[also build test ERROR on linus/master v6.18-rc1 next-20251017]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Srinivas-Kandagatla/ASoC-qdsp6-q6asm-do-not-sleep-while-atomic/20251017-170114
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
patch link:    https://lore.kernel.org/r/20251017085307.4325-13-srinivas.kandagatla%40oss.qualcomm.com
patch subject: [PATCH 12/12] ASoC: qcom: q6asm: Use guard() for spin locks
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20251019/202510191117.BTexj8De-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251019/202510191117.BTexj8De-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202510191117.BTexj8De-lkp@intel.com/

All errors (new ones prefixed by >>):

   sound/soc/qcom/qdsp6/q6asm.c: In function 'q6asm_stream_callback':
>> sound/soc/qcom/qdsp6/q6asm.c:687:41: error: 'struct audio_port_data' has no member named 'hw_ptr'
     687 |                         atomic_set(&port->hw_ptr, token + 1);
         |                                         ^~


vim +687 sound/soc/qcom/qdsp6/q6asm.c

   590	
   591	static int32_t q6asm_stream_callback(struct apr_device *adev,
   592					     struct apr_resp_pkt *data,
   593					     int session_id)
   594	{
   595		struct q6asm *q6asm = dev_get_drvdata(&adev->dev);
   596		struct aprv2_ibasic_rsp_result_t *result;
   597		struct apr_hdr *hdr = &data->hdr;
   598		struct audio_port_data *port;
   599		struct audio_client *ac;
   600		uint32_t client_event = 0;
   601		int ret = 0;
   602	
   603		ac = q6asm_get_audio_client(q6asm, session_id);
   604		if (!ac)/* Audio client might already be freed by now */
   605			return 0;
   606	
   607		result = data->payload;
   608	
   609		switch (hdr->opcode) {
   610		case APR_BASIC_RSP_RESULT:
   611			switch (result->opcode) {
   612			case ASM_SESSION_CMD_PAUSE:
   613				client_event = ASM_CLIENT_EVENT_CMD_PAUSE_DONE;
   614				break;
   615			case ASM_SESSION_CMD_SUSPEND:
   616				client_event = ASM_CLIENT_EVENT_CMD_SUSPEND_DONE;
   617				break;
   618			case ASM_STREAM_CMD_FLUSH:
   619				client_event = ASM_CLIENT_EVENT_CMD_FLUSH_DONE;
   620				break;
   621			case ASM_SESSION_CMD_RUN_V2:
   622				client_event = ASM_CLIENT_EVENT_CMD_RUN_DONE;
   623				break;
   624			case ASM_STREAM_CMD_CLOSE:
   625				client_event = ASM_CLIENT_EVENT_CMD_CLOSE_DONE;
   626				break;
   627			case ASM_STREAM_CMD_FLUSH_READBUFS:
   628				client_event = ASM_CLIENT_EVENT_CMD_OUT_FLUSH_DONE;
   629				break;
   630			case ASM_STREAM_CMD_OPEN_WRITE_V3:
   631			case ASM_STREAM_CMD_OPEN_READ_V3:
   632			case ASM_STREAM_CMD_OPEN_READWRITE_V2:
   633			case ASM_STREAM_CMD_SET_ENCDEC_PARAM:
   634			case ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2:
   635			case ASM_DATA_CMD_REMOVE_INITIAL_SILENCE:
   636			case ASM_DATA_CMD_REMOVE_TRAILING_SILENCE:
   637				if (result->status != 0) {
   638					dev_err(ac->dev,
   639						"cmd = 0x%x returned error = 0x%x\n",
   640						result->opcode, result->status);
   641					ac->result = *result;
   642					wake_up(&ac->cmd_wait);
   643					ret = 0;
   644					goto done;
   645				}
   646				break;
   647			default:
   648				dev_err(ac->dev, "command[0x%x] not expecting rsp\n",
   649					result->opcode);
   650				break;
   651			}
   652	
   653			ac->result = *result;
   654			wake_up(&ac->cmd_wait);
   655	
   656			if (ac->cb)
   657				ac->cb(client_event, hdr->token,
   658				       data->payload, ac->priv);
   659	
   660			ret = 0;
   661			goto done;
   662	
   663		case ASM_DATA_EVENT_WRITE_DONE_V2:
   664			client_event = ASM_CLIENT_EVENT_DATA_WRITE_DONE;
   665			if (ac->io_mode & ASM_SYNC_IO_MODE) {
   666				phys_addr_t phys;
   667				int token = hdr->token & ASM_WRITE_TOKEN_MASK;
   668	
   669				guard(spinlock_irqsave)(&ac->lock);
   670	
   671				port =  &ac->port[SNDRV_PCM_STREAM_PLAYBACK];
   672	
   673				if (!port->buf) {
   674					ret = 0;
   675					goto done;
   676				}
   677	
   678				phys = port->buf[token].phys;
   679	
   680				if (lower_32_bits(phys) != result->opcode ||
   681				    upper_32_bits(phys) != result->status) {
   682					dev_err(ac->dev, "Expected addr %pa\n",
   683						&port->buf[token].phys);
   684					ret = -EINVAL;
   685					goto done;
   686				}
 > 687				atomic_set(&port->hw_ptr, token + 1);
   688			}
   689			break;
   690		case ASM_DATA_EVENT_READ_DONE_V2:
   691			client_event = ASM_CLIENT_EVENT_DATA_READ_DONE;
   692			if (ac->io_mode & ASM_SYNC_IO_MODE) {
   693				struct asm_data_cmd_read_v2_done *done = data->payload;
   694				phys_addr_t phys;
   695	
   696				guard(spinlock_irqsave)(&ac->lock);
   697				port =  &ac->port[SNDRV_PCM_STREAM_CAPTURE];
   698				if (!port->buf) {
   699					ret = 0;
   700					goto done;
   701				}
   702	
   703				phys = port->buf[hdr->token].phys;
   704	
   705				if (upper_32_bits(phys) != done->buf_addr_msw ||
   706				    lower_32_bits(phys) != done->buf_addr_lsw) {
   707					dev_err(ac->dev, "Expected addr %pa %08x-%08x\n",
   708						&port->buf[hdr->token].phys,
   709						done->buf_addr_lsw,
   710						done->buf_addr_msw);
   711					ret = -EINVAL;
   712					goto done;
   713				}
   714			}
   715	
   716			break;
   717		case ASM_DATA_EVENT_RENDERED_EOS:
   718			client_event = ASM_CLIENT_EVENT_CMD_EOS_DONE;
   719			break;
   720		}
   721	
   722		if (ac->cb)
   723			ac->cb(client_event, hdr->token, data->payload, ac->priv);
   724	
   725	done:
   726		kref_put(&ac->refcount, q6asm_audio_client_release);
   727		return ret;
   728	}
   729	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH 12/12] ASoC: qcom: q6asm: Use guard() for spin locks
Posted by Srinivas Kandagatla 3 months, 3 weeks ago

On 10/19/25 5:18 AM, kernel test robot wrote:
> Hi Srinivas,
> 
> kernel test robot noticed the following build errors:
> 
> [auto build test ERROR on broonie-sound/for-next]
> [also build test ERROR on linus/master v6.18-rc1 next-20251017]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Srinivas-Kandagatla/ASoC-qdsp6-q6asm-do-not-sleep-while-atomic/20251017-170114
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
> patch link:    https://lore.kernel.org/r/20251017085307.4325-13-srinivas.kandagatla%40oss.qualcomm.com
> patch subject: [PATCH 12/12] ASoC: qcom: q6asm: Use guard() for spin locks
> config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20251019/202510191117.BTexj8De-lkp@intel.com/config)
> compiler: m68k-linux-gcc (GCC) 15.1.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251019/202510191117.BTexj8De-lkp@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202510191117.BTexj8De-lkp@intel.com/
> 
> All errors (new ones prefixed by >>):
> 
>    sound/soc/qcom/qdsp6/q6asm.c: In function 'q6asm_stream_callback':
>>> sound/soc/qcom/qdsp6/q6asm.c:687:41: error: 'struct audio_port_data' has no member named 'hw_ptr'
>      687 |                         atomic_set(&port->hw_ptr, token + 1);
>          |                                         ^~
> 
> 
> vim +687 sound/soc/qcom/qdsp6/q6asm.c
> 
>    590	
>    591	static int32_t q6asm_stream_callback(struct apr_device *adev,
>    592					     struct apr_resp_pkt *data,
>    593					     int session_id)
>    594	{
>    595		struct q6asm *q6asm = dev_get_drvdata(&adev->dev);
>    596		struct aprv2_ibasic_rsp_result_t *result;
>    597		struct apr_hdr *hdr = &data->hdr;
>    598		struct audio_port_data *port;
>    599		struct audio_client *ac;
>    600		uint32_t client_event = 0;
>    601		int ret = 0;
>    602	
>    603		ac = q6asm_get_audio_client(q6asm, session_id);
>    604		if (!ac)/* Audio client might already be freed by now */
>    605			return 0;
>    606	
>    607		result = data->payload;
>    608	
>    609		switch (hdr->opcode) {
>    610		case APR_BASIC_RSP_RESULT:
>    611			switch (result->opcode) {
>    612			case ASM_SESSION_CMD_PAUSE:
>    613				client_event = ASM_CLIENT_EVENT_CMD_PAUSE_DONE;
>    614				break;
>    615			case ASM_SESSION_CMD_SUSPEND:
>    616				client_event = ASM_CLIENT_EVENT_CMD_SUSPEND_DONE;
>    617				break;
>    618			case ASM_STREAM_CMD_FLUSH:
>    619				client_event = ASM_CLIENT_EVENT_CMD_FLUSH_DONE;
>    620				break;
>    621			case ASM_SESSION_CMD_RUN_V2:
>    622				client_event = ASM_CLIENT_EVENT_CMD_RUN_DONE;
>    623				break;
>    624			case ASM_STREAM_CMD_CLOSE:
>    625				client_event = ASM_CLIENT_EVENT_CMD_CLOSE_DONE;
>    626				break;
>    627			case ASM_STREAM_CMD_FLUSH_READBUFS:
>    628				client_event = ASM_CLIENT_EVENT_CMD_OUT_FLUSH_DONE;
>    629				break;
>    630			case ASM_STREAM_CMD_OPEN_WRITE_V3:
>    631			case ASM_STREAM_CMD_OPEN_READ_V3:
>    632			case ASM_STREAM_CMD_OPEN_READWRITE_V2:
>    633			case ASM_STREAM_CMD_SET_ENCDEC_PARAM:
>    634			case ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2:
>    635			case ASM_DATA_CMD_REMOVE_INITIAL_SILENCE:
>    636			case ASM_DATA_CMD_REMOVE_TRAILING_SILENCE:
>    637				if (result->status != 0) {
>    638					dev_err(ac->dev,
>    639						"cmd = 0x%x returned error = 0x%x\n",
>    640						result->opcode, result->status);
>    641					ac->result = *result;
>    642					wake_up(&ac->cmd_wait);
>    643					ret = 0;
>    644					goto done;
>    645				}
>    646				break;
>    647			default:
>    648				dev_err(ac->dev, "command[0x%x] not expecting rsp\n",
>    649					result->opcode);
>    650				break;
>    651			}
>    652	
>    653			ac->result = *result;
>    654			wake_up(&ac->cmd_wait);
>    655	
>    656			if (ac->cb)
>    657				ac->cb(client_event, hdr->token,
>    658				       data->payload, ac->priv);
>    659	
>    660			ret = 0;
>    661			goto done;
>    662	
>    663		case ASM_DATA_EVENT_WRITE_DONE_V2:
>    664			client_event = ASM_CLIENT_EVENT_DATA_WRITE_DONE;
>    665			if (ac->io_mode & ASM_SYNC_IO_MODE) {
>    666				phys_addr_t phys;
>    667				int token = hdr->token & ASM_WRITE_TOKEN_MASK;
>    668	
>    669				guard(spinlock_irqsave)(&ac->lock);
>    670	
>    671				port =  &ac->port[SNDRV_PCM_STREAM_PLAYBACK];
>    672	
>    673				if (!port->buf) {
>    674					ret = 0;
>    675					goto done;
>    676				}
>    677	
>    678				phys = port->buf[token].phys;
>    679	
>    680				if (lower_32_bits(phys) != result->opcode ||
>    681				    upper_32_bits(phys) != result->status) {
>    682					dev_err(ac->dev, "Expected addr %pa\n",
>    683						&port->buf[token].phys);
>    684					ret = -EINVAL;
>    685					goto done;
>    686				}
>  > 687				atomic_set(&port->hw_ptr, token + 1);

Ah.. looks like left over from adsp patches

will remove this and send a v2.

--srini>    688			}
>    689			break;
>    690		case ASM_DATA_EVENT_READ_DONE_V2:
>    691			client_event = ASM_CLIENT_EVENT_DATA_READ_DONE;
>    692			if (ac->io_mode & ASM_SYNC_IO_MODE) {
>    693				struct asm_data_cmd_read_v2_done *done = data->payload;
>    694				phys_addr_t phys;
>    695	
>    696				guard(spinlock_irqsave)(&ac->lock);
>    697				port =  &ac->port[SNDRV_PCM_STREAM_CAPTURE];
>    698				if (!port->buf) {
>    699					ret = 0;
>    700					goto done;
>    701				}
>    702	
>    703				phys = port->buf[hdr->token].phys;
>    704	
>    705				if (upper_32_bits(phys) != done->buf_addr_msw ||
>    706				    lower_32_bits(phys) != done->buf_addr_lsw) {
>    707					dev_err(ac->dev, "Expected addr %pa %08x-%08x\n",
>    708						&port->buf[hdr->token].phys,
>    709						done->buf_addr_lsw,
>    710						done->buf_addr_msw);
>    711					ret = -EINVAL;
>    712					goto done;
>    713				}
>    714			}
>    715	
>    716			break;
>    717		case ASM_DATA_EVENT_RENDERED_EOS:
>    718			client_event = ASM_CLIENT_EVENT_CMD_EOS_DONE;
>    719			break;
>    720		}
>    721	
>    722		if (ac->cb)
>    723			ac->cb(client_event, hdr->token, data->payload, ac->priv);
>    724	
>    725	done:
>    726		kref_put(&ac->refcount, q6asm_audio_client_release);
>    727		return ret;
>    728	}
>    729	
>