All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@linaro.org>
To: Wesley Cheng <quic_wcheng@quicinc.com>
Cc: linux-sound@vger.kernel.org
Subject: [bug report] ALSA: usb-audio: qcom: Introduce QC USB SND offloading support
Date: Tue, 15 Apr 2025 13:27:52 +0300	[thread overview]
Message-ID: <Z_40qL4JnyjR4j0O@stanley.mountain> (raw)

Hello Wesley Cheng,

Commit 326bbc348298 ("ALSA: usb-audio: qcom: Introduce QC USB SND
offloading support") from Apr 9, 2025 (linux-next), leads to the
following Smatch static checker warning:

	sound/usb/qcom/qc_audio_offload.c:1364 prepare_qmi_response()
	warn: missing error code here? 'snd_soc_usb_find_priv_data()' failed. 'ret' = '0'

sound/usb/qcom/qc_audio_offload.c
    1335 static int prepare_qmi_response(struct snd_usb_substream *subs,
    1336                                 struct qmi_uaudio_stream_req_msg_v01 *req_msg,
    1337                                 struct qmi_uaudio_stream_resp_msg_v01 *resp,
    1338                                 int info_idx)
    1339 {
    1340         struct q6usb_offload *data;
    1341         int pcm_dev_num;
    1342         int card_num;
    1343         u8 *xfer_buf = NULL;
    1344         int ret;
    1345 
    1346         pcm_dev_num = (req_msg->usb_token & QMI_STREAM_REQ_DEV_NUM_MASK) >> 8;
    1347         card_num = (req_msg->usb_token & QMI_STREAM_REQ_CARD_NUM_MASK) >> 16;
    1348 
    1349         if (!uadev[card_num].ctrl_intf) {
    1350                 dev_err(&subs->dev->dev, "audio ctrl intf info not cached\n");
    1351                 ret = -ENODEV;
    1352                 goto err;
    1353         }
    1354 
    1355         ret = uaudio_populate_uac_desc(subs, resp);
    1356         if (ret < 0)
    1357                 goto err;
    1358 
    1359         resp->slot_id = subs->dev->slot_id;
    1360         resp->slot_id_valid = 1;
    1361 
    1362         data = snd_soc_usb_find_priv_data(uaudio_qdev->auxdev->dev.parent);
    1363         if (!data)
--> 1364                 goto err;

error code?  It's probably better to return directly because it often
helps avoid "forgot set the error code" bugs.  Also it's more readable.

    1365 
    1366         uaudio_qdev->data = data;
    1367 
    1368         resp->std_as_opr_intf_desc_valid = 1;
    1369         ret = uaudio_endpoint_setup(subs, subs->data_endpoint, card_num,
    1370                                     &resp->xhci_mem_info.tr_data,
    1371                                     &resp->std_as_data_ep_desc);
    1372         if (ret < 0)
    1373                 goto err;
    1374 
    1375         resp->std_as_data_ep_desc_valid = 1;
    1376 
    1377         if (subs->sync_endpoint) {
    1378                 ret = uaudio_endpoint_setup(subs, subs->sync_endpoint, card_num,
    1379                                             &resp->xhci_mem_info.tr_sync,
    1380                                             &resp->std_as_sync_ep_desc);
    1381                 if (ret < 0)
    1382                         goto drop_data_ep;
    1383 
    1384                 resp->std_as_sync_ep_desc_valid = 1;
    1385         }
    1386 
    1387         resp->interrupter_num_valid = 1;
    1388         resp->controller_num_valid = 0;
    1389         ret = usb_get_controller_id(subs->dev);
    1390         if (ret >= 0) {
    1391                 resp->controller_num = ret;
    1392                 resp->controller_num_valid = 1;
    1393         }
    1394 
    1395         /* event ring */
    1396         ret = uaudio_event_ring_setup(subs, card_num,
    1397                                       &resp->xhci_mem_info.evt_ring);
    1398         if (ret < 0)
    1399                 goto drop_sync_ep;
    1400 
    1401         uaudio_qdev->er_mapped = true;
    1402         resp->interrupter_num = xhci_sideband_interrupter_id(uadev[card_num].sb);
    1403 
    1404         resp->speed_info = get_speed_info(subs->dev->speed);
    1405         if (resp->speed_info == USB_QMI_DEVICE_SPEED_INVALID_V01) {
    1406                 ret = -ENODEV;
    1407                 goto free_sec_ring;
    1408         }
    1409 
    1410         resp->speed_info_valid = 1;
    1411 
    1412         ret = uaudio_transfer_buffer_setup(subs, xfer_buf, req_msg->xfer_buff_size,
    1413                                            &resp->xhci_mem_info.xfer_buff);
    1414         if (ret < 0) {
    1415                 ret = -ENOMEM;
    1416                 goto free_sec_ring;
    1417         }
    1418 
    1419         resp->xhci_mem_info_valid = 1;
    1420 
    1421         if (!atomic_read(&uadev[card_num].in_use)) {
    1422                 kref_init(&uadev[card_num].kref);
    1423                 init_waitqueue_head(&uadev[card_num].disconnect_wq);
    1424                 uadev[card_num].num_intf =
    1425                         subs->dev->config->desc.bNumInterfaces;
    1426                 uadev[card_num].info = kcalloc(uadev[card_num].num_intf,
    1427                                                sizeof(struct intf_info),
    1428                                                GFP_KERNEL);
    1429                 if (!uadev[card_num].info) {
    1430                         ret = -ENOMEM;
    1431                         goto unmap_er;
    1432                 }
    1433                 uadev[card_num].udev = subs->dev;
    1434                 atomic_set(&uadev[card_num].in_use, 1);
    1435         } else {
    1436                 kref_get(&uadev[card_num].kref);
    1437         }
    1438 
    1439         uadev[card_num].usb_core_id = resp->controller_num;
    1440 
    1441         /* cache intf specific info to use it for unmap and free xfer buf */
    1442         uadev[card_num].info[info_idx].data_xfer_ring_va =
    1443                                         IOVA_MASK(resp->xhci_mem_info.tr_data.va);
    1444         uadev[card_num].info[info_idx].data_xfer_ring_size = PAGE_SIZE;
    1445         uadev[card_num].info[info_idx].sync_xfer_ring_va =
    1446                                         IOVA_MASK(resp->xhci_mem_info.tr_sync.va);
    1447         uadev[card_num].info[info_idx].sync_xfer_ring_size = PAGE_SIZE;
    1448         uadev[card_num].info[info_idx].xfer_buf_va =
    1449                                         IOVA_MASK(resp->xhci_mem_info.xfer_buff.va);
    1450         uadev[card_num].info[info_idx].xfer_buf_pa =
    1451                                         resp->xhci_mem_info.xfer_buff.pa;
    1452         uadev[card_num].info[info_idx].xfer_buf_size =
    1453                                         resp->xhci_mem_info.xfer_buff.size;
    1454         uadev[card_num].info[info_idx].data_ep_pipe = subs->data_endpoint ?
    1455                                                 subs->data_endpoint->pipe : 0;
    1456         uadev[card_num].info[info_idx].sync_ep_pipe = subs->sync_endpoint ?
    1457                                                 subs->sync_endpoint->pipe : 0;
    1458         uadev[card_num].info[info_idx].data_ep_idx = subs->data_endpoint ?
    1459                                                 subs->data_endpoint->ep_num : 0;
    1460         uadev[card_num].info[info_idx].sync_ep_idx = subs->sync_endpoint ?
    1461                                                 subs->sync_endpoint->ep_num : 0;
    1462         uadev[card_num].info[info_idx].xfer_buf = xfer_buf;
    1463         uadev[card_num].info[info_idx].pcm_card_num = card_num;
    1464         uadev[card_num].info[info_idx].pcm_dev_num = pcm_dev_num;
    1465         uadev[card_num].info[info_idx].direction = subs->direction;
    1466         uadev[card_num].info[info_idx].intf_num = subs->cur_audiofmt->iface;
    1467         uadev[card_num].info[info_idx].in_use = true;
    1468 
    1469         set_bit(card_num, &uaudio_qdev->card_slot);
    1470 
    1471         return 0;
    1472 
    1473 unmap_er:
    1474         uaudio_iommu_unmap(MEM_EVENT_RING, IOVA_BASE, PAGE_SIZE, PAGE_SIZE);
    1475 free_sec_ring:
    1476         xhci_sideband_remove_interrupter(uadev[card_num].sb);
    1477 drop_sync_ep:
    1478         if (subs->sync_endpoint) {
    1479                 uaudio_iommu_unmap(MEM_XFER_RING,
    1480                                    IOVA_MASK(resp->xhci_mem_info.tr_sync.va),
    1481                                    PAGE_SIZE, PAGE_SIZE);
    1482                 xhci_sideband_remove_endpoint(uadev[card_num].sb,
    1483                         usb_pipe_endpoint(subs->dev, subs->sync_endpoint->pipe));
    1484         }
    1485 drop_data_ep:
    1486         uaudio_iommu_unmap(MEM_XFER_RING, IOVA_MASK(resp->xhci_mem_info.tr_data.va),
    1487                            PAGE_SIZE, PAGE_SIZE);
    1488         xhci_sideband_remove_endpoint(uadev[card_num].sb,
    1489                         usb_pipe_endpoint(subs->dev, subs->data_endpoint->pipe));
    1490 
    1491 err:
    1492         return ret;
    1493 }

regards,
dan carpenter

             reply	other threads:[~2025-04-15 10:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-15 10:27 Dan Carpenter [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-04-15 10:45 [bug report] ALSA: usb-audio: qcom: Introduce QC USB SND offloading support Dan Carpenter
2025-04-15 10:46 Dan Carpenter
2025-04-15 10:46 Dan Carpenter
2025-04-15 10:47 Dan Carpenter

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=Z_40qL4JnyjR4j0O@stanley.mountain \
    --to=dan.carpenter@linaro.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=quic_wcheng@quicinc.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.