Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: Mario Kicherer <dev@kicherer.org>
Cc: alsa-devel@alsa-project.org
Subject: Re: [PATCH v2] MIDI driver for Behringer BCD2000 USB device
Date: Thu, 06 Feb 2014 21:51:12 +0100	[thread overview]
Message-ID: <52F3F5C0.7000805@ladisch.de> (raw)
In-Reply-To: <52F3B34A.3090209@kicherer.org>

Mario Kicherer wrote:
> On 06.02.2014 10:21, Clemens Ladisch wrote:
>>> +config SND_USB_BCD2000
>>> +    tristate "Behringer BCD2000 MIDI driver"
>>> +    select SND_HWDEP
>>
>> Why HWDEP?
>
> I admit, I copied this from the other modules (caiaq I believe). After
> grepping the documentation, I'm not sure if I need this. Should I remove
> it?

Yes; you aren't using any snd_hwdep* functions.

>> There is no need to have "usb" in the module name if that is the only
>> bus this device works with.
>
> Okay, after looking at the other modules I thought that it is common to
> use the "snd-usb" prefix.

The USB audio class driver uses "snd-usb-audio" because "snd-audio" would
be completely useless as a name.  Other drivers then blindly copied this.

> Should I remove it? I find it useful, e.g., to recognize it in a "lsmod".

"snd-bcd2000" would not be recognizable?

>>> -obj-$(CONFIG_SND) += misc/ usx2y/ caiaq/ 6fire/ hiface/
>>> +obj-$(CONFIG_SND) += misc/ usx2y/ caiaq/ 6fire/ hiface/ bcd2000/
>>
>> If there is only a single source file, just put it into misc/.
>> If you plan to have multiple source files, then this file should have
>> "_midi" in its name.
>
> Okay, I thought that the code is short enough to put everything in one
> file but I think with the audio part it would be best to split the file.
> I can move it to misc/ or do you think an own subdirectory is okay to
> avoid moving it in later versions?

It doesn't make much sense to put it into a directory that you know you
will move it out of later.

>> ALSA does not require full MIDI commands, and handles running status.
>
> Oh, okay. So, should I just pass everything through to
> snd_rawmidi_receive() ?

Yes.

>>> +static void bcd2000_midi_output_done(struct urb *urb)
>>> +{
>>> ...
>>> +    if (!bcd2k->midi_out_substream)
>>> +        return;
>>> +
>>> +    bcd2000_midi_send(bcd2k, bcd2k->midi_out_substream);
>>
>> The midi_out_substream field gets modified asynchronously by the trigger
>> callback; this might happen between these two statements.
>>
>> Assuming that setting a pointer is atomic, use ACCESS_ONCE.
>
> You mean like this:
>
> struct snd_rawmidi_substream * midi_out_substream;
> midi_out_substream = ACCESS_ONCE(bcd2k->midi_out_substream);
> if (!midi_out_substream)
>     return;
> bcd2000_midi_send(bcd2k, midi_out_substream);

Yes.

The code that modifies this field also needs ACCESS_ONCE.

>>> +static void bcd2000_init_midi(struct bcd2000 *bcd2k)
>>> +{
>>> +    bcd2k->midi_in_urb = usb_alloc_urb(0, GFP_KERNEL);
>>> +    bcd2k->midi_out_urb = usb_alloc_urb(0, GFP_KERNEL);
>>
>> Error checking.
>
> Okay, I guess I should close everything I opened in this module before
> or would a "return" suffice?

Typically, in case of an error, a function is responsible to revert
everything allocated in this function, i.e.:

static int bcd2000_init_midi(struct bcd2000 *bcd2k)
{
	bcd2k->midi_in_urb = usb_alloc_urb(0, GFP_KERNEL);
	if (!bcd2k->midi_in_urb)
		return -ENOMEM;
	bcd2k->midi_out_urb = usb_alloc_urb(0, GFP_KERNEL);
	if (!bcd2k->midi_out_urb) {
		usb_free_urb(bcd2k->midi_in_urb);
		return -ENOMEM;
	}
	...


Regards,
Clemens

      reply	other threads:[~2014-02-06 20:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-05 20:10 [PATCH v2] MIDI driver for Behringer BCD2000 USB device Mario Kicherer
2014-02-05 22:32 ` Daniel Mack
2014-02-06  8:41   ` Takashi Iwai
2014-02-06 16:07   ` Mario Kicherer
2014-02-06 16:16     ` Daniel Mack
2014-02-06  9:21 ` Clemens Ladisch
2014-02-06 16:07   ` Mario Kicherer
2014-02-06 20:51     ` Clemens Ladisch [this message]

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=52F3F5C0.7000805@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=dev@kicherer.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