cregit-Linux how code gets into the kernel

Release 4.7 sound/usb/line6/midibuf.c

Directory: sound/usb/line6
/*
 * Line 6 Linux USB driver
 *
 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
 *
 *      This program is free software; you can redistribute it and/or
 *      modify it under the terms of the GNU General Public License as
 *      published by the Free Software Foundation, version 2.
 *
 */

#include <linux/slab.h>

#include "midibuf.h"


static int midibuf_message_length(unsigned char code) { int message_length; if (code < 0x80) message_length = -1; else if (code < 0xf0) { static const int length[] = { 3, 3, 3, 3, 2, 2, 3 }; message_length = length[(code >> 4) - 8]; } else { /* Note that according to the MIDI specification 0xf2 is the "Song Position Pointer", but this is used by Line 6 to send sysex messages to the host. */ static const int length[] = { -1, 2, -1, 2, -1, -1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1 }; message_length = length[code & 0x0f]; } return message_length; }

Contributors

PersonTokensPropCommitsCommitProp
markus grabnermarkus grabner11286.82%125.00%
domagoj trsandomagoj trsan1511.63%125.00%
chris rorvickchris rorvick10.78%125.00%
greg kroah-hartmangreg kroah-hartman10.78%125.00%
Total129100.00%4100.00%


static int midibuf_is_empty(struct midi_buffer *this) { return (this->pos_read == this->pos_write) && !this->full; }

Contributors

PersonTokensPropCommitsCommitProp
markus grabnermarkus grabner2696.30%150.00%
stefan hajnoczistefan hajnoczi13.70%150.00%
Total27100.00%2100.00%


static int midibuf_is_full(struct midi_buffer *this) { return this->full; }

Contributors

PersonTokensPropCommitsCommitProp
markus grabnermarkus grabner1593.75%150.00%
stefan hajnoczistefan hajnoczi16.25%150.00%
Total16100.00%2100.00%


void line6_midibuf_reset(struct midi_buffer *this) { this->pos_read = this->pos_write = this->full = 0; this->command_prev = -1; }

Contributors

PersonTokensPropCommitsCommitProp
markus grabnermarkus grabner3096.77%266.67%
stefan hajnoczistefan hajnoczi13.23%133.33%
Total31100.00%3100.00%


int line6_midibuf_init(struct midi_buffer *this, int size, int split) { this->buf = kmalloc(size, GFP_KERNEL); if (this->buf == NULL) return -ENOMEM; this->size = size; this->split = split; line6_midibuf_reset(this); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
markus grabnermarkus grabner5796.61%250.00%
greg kroah-hartmangreg kroah-hartman11.69%125.00%
stefan hajnoczistefan hajnoczi11.69%125.00%
Total59100.00%4100.00%


int line6_midibuf_bytes_free(struct midi_buffer *this) { return midibuf_is_full(this) ? 0 : (this->pos_read - this->pos_write + this->size - 1) % this->size + 1; }

Contributors

PersonTokensPropCommitsCommitProp
markus grabnermarkus grabner3997.50%266.67%
stefan hajnoczistefan hajnoczi12.50%133.33%
Total40100.00%3100.00%


int line6_midibuf_bytes_used(struct midi_buffer *this) { return midibuf_is_empty(this) ? 0 : (this->pos_write - this->pos_read + this->size - 1) % this->size + 1; }

Contributors

PersonTokensPropCommitsCommitProp
markus grabnermarkus grabner3997.50%266.67%
stefan hajnoczistefan hajnoczi12.50%133.33%
Total40100.00%3100.00%


int line6_midibuf_write(struct midi_buffer *this, unsigned char *data, int length) { int bytes_free; int length1, length2; int skip_active_sense = 0; if (midibuf_is_full(this) || (length <= 0)) return 0; /* skip trailing active sense */ if (data[length - 1] == 0xfe) { --length; skip_active_sense = 1; } bytes_free = line6_midibuf_bytes_free(this); if (length > bytes_free) length = bytes_free; if (length > 0) { length1 = this->size - this->pos_write; if (length < length1) { /* no buffer wraparound */ memcpy(this->buf + this->pos_write, data, length); this->pos_write += length; } else { /* buffer wraparound */ length2 = length - length1; memcpy(this->buf + this->pos_write, data, length1); memcpy(this->buf, data + length1, length2); this->pos_write = length2; } if (this->pos_write == this->pos_read) this->full = 1; } return length + skip_active_sense; }

Contributors

PersonTokensPropCommitsCommitProp
markus grabnermarkus grabner19799.49%266.67%
stefan hajnoczistefan hajnoczi10.51%133.33%
Total198100.00%3100.00%


int line6_midibuf_read(struct midi_buffer *this, unsigned char *data, int length) { int bytes_used; int length1, length2; int command; int midi_length; int repeat = 0; int i; /* we need to be able to store at least a 3 byte MIDI message */ if (length < 3) return -EINVAL; if (midibuf_is_empty(this)) return 0; bytes_used = line6_midibuf_bytes_used(this); if (length > bytes_used) length = bytes_used; length1 = this->size - this->pos_read; /* check MIDI command length */ command = this->buf[this->pos_read]; if (command & 0x80) { midi_length = midibuf_message_length(command); this->command_prev = command; } else { if (this->command_prev > 0) { int midi_length_prev = midibuf_message_length(this->command_prev); if (midi_length_prev > 0) { midi_length = midi_length_prev - 1; repeat = 1; } else midi_length = -1; } else midi_length = -1; } if (midi_length < 0) { /* search for end of message */ if (length < length1) { /* no buffer wraparound */ for (i = 1; i < length; ++i) if (this->buf[this->pos_read + i] & 0x80) break; midi_length = i; } else { /* buffer wraparound */ length2 = length - length1; for (i = 1; i < length1; ++i) if (this->buf[this->pos_read + i] & 0x80) break; if (i < length1) midi_length = i; else { for (i = 0; i < length2; ++i) if (this->buf[i] & 0x80) break; midi_length = length1 + i; } } if (midi_length == length) midi_length = -1; /* end of message not found */ } if (midi_length < 0) { if (!this->split) return 0; /* command is not yet complete */ } else { if (length < midi_length) return 0; /* command is not yet complete */ length = midi_length; } if (length < length1) { /* no buffer wraparound */ memcpy(data + repeat, this->buf + this->pos_read, length); this->pos_read += length; } else { /* buffer wraparound */ length2 = length - length1; memcpy(data + repeat, this->buf + this->pos_read, length1); memcpy(data + repeat + length1, this->buf, length2); this->pos_read = length2; } if (repeat) data[0] = this->command_prev; this->full = 0; return length + repeat; }

Contributors

PersonTokensPropCommitsCommitProp
markus grabnermarkus grabner45899.57%250.00%
greg kroah-hartmangreg kroah-hartman10.22%125.00%
stefan hajnoczistefan hajnoczi10.22%125.00%
Total460100.00%4100.00%


int line6_midibuf_ignore(struct midi_buffer *this, int length) { int bytes_used = line6_midibuf_bytes_used(this); if (length > bytes_used) length = bytes_used; this->pos_read = (this->pos_read + length) % this->size; this->full = 0; return length; }

Contributors

PersonTokensPropCommitsCommitProp
markus grabnermarkus grabner5598.21%266.67%
stefan hajnoczistefan hajnoczi11.79%133.33%
Total56100.00%3100.00%


void line6_midibuf_destroy(struct midi_buffer *this) { kfree(this->buf); this->buf = NULL; }

Contributors

PersonTokensPropCommitsCommitProp
markus grabnermarkus grabner2191.30%250.00%
stefan hajnoczistefan hajnoczi14.35%125.00%
greg kroah-hartmangreg kroah-hartman14.35%125.00%
Total23100.00%4100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
markus grabnermarkus grabner105597.15%222.22%
domagoj trsandomagoj trsan151.38%111.11%
stefan hajnoczistefan hajnoczi100.92%111.11%
greg kroah-hartmangreg kroah-hartman40.37%333.33%
chris rorvickchris rorvick20.18%222.22%
Total1086100.00%9100.00%
Directory: sound/usb/line6
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
{% endraw %}