Skip to content

Commit 0d9eb7e

Browse files
takaswietiwai
authored andcommitted
ALSA: fireface: add field for the number of messages copied to user space
Current structure includes no field to express the number of messages copied to user space, thus user space application needs to information out of the structure to parse the content of structure. This commit adds a field to express the number of messages copied to user space since It is more preferable to use self-contained structure. Kees Cook proposed an idea of annotation for bound of flexible arrays in his future improvement for flexible-length array in kernel. The additional field for message count is suitable to the idea as well. Reference: https://people.kernel.org/kees/bounded-flexible-arrays-in-c Signed-off-by: Takashi Sakamoto <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent d045bce commit 0d9eb7e

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

include/uapi/sound/firewire.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct snd_firewire_event_motu_register_dsp_change {
7878
* operating hardware knob.
7979
*
8080
* @type: Fixed to SNDRV_FIREWIRE_EVENT_FF400_MESSAGE.
81+
* @message_count: The number of messages.
8182
* @messages.message: The messages expressing hardware knob operation.
8283
* @messages.tstamp: The isochronous cycle at which the request subaction of asynchronous
8384
* transaction was sent to deliver the message. It has 16 bit unsigned integer
@@ -89,6 +90,7 @@ struct snd_firewire_event_motu_register_dsp_change {
8990
*/
9091
struct snd_firewire_event_ff400_message {
9192
unsigned int type;
93+
unsigned int message_count;
9294
struct {
9395
__u32 message;
9496
__u32 tstamp;

sound/firewire/fireface/ff-protocol-former.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -677,23 +677,19 @@ static void ff400_handle_msg(struct snd_ff *ff, unsigned int offset, const __le3
677677

678678
static long ff400_copy_msg_to_user(struct snd_ff *ff, char __user *buf, long count)
679679
{
680+
struct snd_firewire_event_ff400_message ev = {
681+
.type = SNDRV_FIREWIRE_EVENT_FF400_MESSAGE,
682+
.message_count = 0,
683+
};
680684
struct ff400_msg_parser *parser = ff->msg_parser;
681-
u32 type = SNDRV_FIREWIRE_EVENT_FF400_MESSAGE;
682685
long consumed = 0;
683-
int ret = 0;
686+
long ret = 0;
684687

685-
if (count < 8)
688+
if (count < sizeof(ev) || parser->pull_pos == parser->push_pos)
686689
return 0;
687690

688-
spin_unlock_irq(&ff->lock);
689-
if (copy_to_user(buf, &type, sizeof(type)))
690-
ret = -EFAULT;
691-
spin_lock_irq(&ff->lock);
692-
if (ret)
693-
return ret;
694-
695-
count -= sizeof(type);
696-
consumed += sizeof(type);
691+
count -= sizeof(ev);
692+
consumed += sizeof(ev);
697693

698694
while (count >= sizeof(*parser->msgs) && parser->pull_pos != parser->push_pos) {
699695
spin_unlock_irq(&ff->lock);
@@ -707,10 +703,18 @@ static long ff400_copy_msg_to_user(struct snd_ff *ff, char __user *buf, long cou
707703
++parser->pull_pos;
708704
if (parser->pull_pos >= FF400_QUEUE_SIZE)
709705
parser->pull_pos = 0;
706+
++ev.message_count;
710707
count -= sizeof(*parser->msgs);
711708
consumed += sizeof(*parser->msgs);
712709
}
713710

711+
spin_unlock_irq(&ff->lock);
712+
if (copy_to_user(buf, &ev, sizeof(ev)))
713+
ret = -EFAULT;
714+
spin_lock_irq(&ff->lock);
715+
if (ret)
716+
return ret;
717+
714718
return consumed;
715719
}
716720

0 commit comments

Comments
 (0)