All of lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: Antonio Ospite <ospite@studenti.unina.it>
Cc: alsa-devel@alsa-project.org, Takashi Iwai <tiwai@suse.de>,
	Antonio Ospite <ao2@amarulasolutions.com>,
	fchecconi@gmail.com, Pietro Cipriano <p.cipriano@m2tech.biz>,
	alberto@amarulasolutions.com,
	Michael Trimarchi <michael@amarulasolutions.com>
Subject: Re: [PATCH] Add M2Tech hiFace USB-SPDIF driver
Date: Tue, 12 Feb 2013 15:29:19 +0100	[thread overview]
Message-ID: <511A51BF.6000602@ladisch.de> (raw)
In-Reply-To: <20130212133521.39628e4aef556560b8b14dd8@studenti.unina.it>

Antonio Ospite wrote:
> Clemens Ladisch <clemens@ladisch.de> wrote:
>> Antonio Ospite wrote:
>>> I also noticed that many drivers under sound/usb/ have text in the Kconfig
>>> entry stating "Say Y here to include support for ..." but I only see "[N/m/?]"
>>> as options when I run "make oldconfig" maybe because of some dependency, I am
>>> not sure, should such text be removed in order to avoid confusion?
>>
>> It allows only "m" for "module" because some dependencies already
>> are modules.
>
> Right, but should the sentence about "Say Y..." be removed here and in
> the other drivers?

If you want to, replace it with "Select this ...".

>>> +MODULE_SUPPORTED_DEVICE("{{HiFace, Evo}}");
>>
>> MODULE_SUPPORTED_DEVICE isn't actually used at the moment, but if you
>> use it, you should include all supported devices.  Or is this a name
>> for the entire family?
>>
>> (But I guess the name is "Evo", not " Evo".)
>
> OK, I'll list all supported devices following the format used in
> sound/usb/caiaq/device.c, which AFAICS is "{Manufacturer, Device Name}"
> for each entry, that is still with a leading space before the device
> name, or is that wrong in your opinion?

Most driver take care to have no spaces.

>>> +	if (quirk && quirk->device_name)
>>> +		strcpy(card->shortname, quirk->device_name);
>>> +	else
>>> +		strcpy(card->shortname, "M2Tech generic audio");
>>
>> Don't the devices have their name in the device descriptor?
>
> It looks like the iProduct field is not reliable enough, different
> devices could have the same value there.

The iProduct field is the number of the string descriptor.
That string might be useful at least in the non-quirk case
(which shouldn't happen in the first case AFAICS).

>>> +	ret = usb_control_msg(device, usb_sndctrlpipe(device, 0),
>>> +				0xb0,
>>> +				USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
>>> +				rate_value[rt->rate], 0, NULL, 0, 100);
>>
>> You must not do DMA from either the stack or from static module data, so
>> you have to copy this byte into kmalloc'ed memory (like snd_usb_ctl_msg()
>> does).
>
> Well, your remark is valid for when the "void *data" argument of
> usb_control_msg() is used, but I am just using the "value" argument here
> which is a single u16 value, not a buffer address. So I think I can
> leave this part as is, can't I?

Yes; sorry.

>>> +static int hiface_pcm_playback(struct pcm_substream *sub,
>>> +		struct pcm_urb *urb)
>>> +{
>>> +	/* XXX Can an invalid format make it to here?
>>
>> No.
>
> So I can remove the check, thanks, or would it be OK to make it a
> WARN_ON or a BUG_ON?

BUG_ON would blow up the kernel, and is appropriate when you
cannot continue at all.  Use at most a WARN_ON, but it would be
perfectly reasonable to not check at all.

>>> +static void hiface_pcm_out_urb_handler(struct urb *usb_urb)
>>> +{
>>> +	if (usb_urb->status || rt->panic || rt->stream_state == STREAM_STOPPING)
>>> +		return;
>>
>> In some error cases, you might consider stopping the stream.
>
> You mean I should check explicitly for some values of usb_urb->status
> and stop the stream if they happen? Like you do in
> sound/usb/misc/ua101.c::capture_urb_complete()?

If only one URB doesn't get delivered for whatever reason, how should
the driver react?  If you just exit from the completion handler, the
driver will continue to fill and queue all the other URBs.
And what happens when the device is unplugged?

>>> +		ret = hiface_pcm_playback(sub, out_urb);
>>> +		if (ret < 0) {
>>> +			spin_unlock_irqrestore(&sub->lock, flags);
>>> +			goto out_fail;
>>> +		}
>>> +...
>>> +out_fail:
>>> +	usb_submit_urb(&out_urb->instance, GFP_ATOMIC);
>>
>> Same here.
>
> If I remove the check for format in hiface_pcm_playback() then this
> label would go away too and this won't be an error path anymore, but
> maybe you meant that I need to check the return value of usb_submit_urb
> () and stop the stream when the latter fails?

At the moment, you are trying to queue a URB with invalid samples.

>>> +			snd_pcm_stop(rt->playback.instance,
>>> +					SNDRV_PCM_STATE_XRUN);
>>
>> This requres locking the stream with something like
>> snd_pcm_stream_lock_irq().
>
> OK, but would you mind elaborating a little more why this is needed?
>
> I do not see other drivers doing that,

sound/firewire/{amdtp,isight}.c do.  I've never said that all those
other drivers would be correct.  (And you have to be careful to avoid
deadlocks.)

> and BTW I see also that some other drivers not calling snd_pcm_stop()
> at all, e.g. it is commented in sound/usb/endpoint.c::snd_complete_urb().

It's commented because it would crash.  That driver isn't in a very
good state regarding state changes.


Regards,
Clemens

  reply	other threads:[~2013-02-12 14:29 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-10 23:11 [PATCH] Add M2Tech hiFace USB-SPDIF driver Antonio Ospite
2013-02-11  8:53 ` Clemens Ladisch
2013-02-12 12:35   ` Antonio Ospite
2013-02-12 14:29     ` Clemens Ladisch [this message]
2013-02-12 15:29       ` Takashi Iwai
2013-02-13 14:09       ` Antonio Ospite
2013-02-13 17:11 ` [PATCH v2] " Antonio Ospite
2013-02-22 10:48   ` Antonio Ospite
2013-02-22 12:52     ` Takashi Iwai
2013-02-22 13:31       ` Antonio Ospite
2013-02-22 14:09         ` Takashi Iwai
2013-02-22 12:53   ` Takashi Iwai
2013-04-28 21:09     ` Antonio Ospite
2013-05-29 12:24       ` Takashi Iwai
2013-06-03 21:40         ` Antonio Ospite
2013-02-22 16:12   ` Daniel Mack
2013-02-22 16:18     ` Takashi Iwai
2013-04-28 20:59     ` Antonio Ospite
2013-04-20 20:15   ` Daniel Mack
2013-04-22  7:40     ` Pavel Hofman
     [not found]       ` <5174F560.8050502@m2tech.biz>
2013-04-22  8:37         ` Pavel Hofman
2013-04-22  9:14     ` Antonio Ospite
2013-06-21 22:14 ` [PATCH v3] " Antonio Ospite
2013-06-24  7:45   ` Takashi Iwai
  -- strict thread matches above, loose matches on Subject: below --
2013-02-10 23:06 [PATCH] " Antonio Ospite

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=511A51BF.6000602@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=alberto@amarulasolutions.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=ao2@amarulasolutions.com \
    --cc=fchecconi@gmail.com \
    --cc=michael@amarulasolutions.com \
    --cc=ospite@studenti.unina.it \
    --cc=p.cipriano@m2tech.biz \
    --cc=tiwai@suse.de \
    /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.