Commit 17596a80d3b57763f6d111fa95416559bad9c8dc

Authored by Marcin Ślusarz
Committed by Jaroslav Kysela
1 parent a780c0aeb3

[ALSA] rawmidi: let sparse know what is going on _for real_

snd_rawmidi_kernel_read1/write1 weren't annotated but used
copy_to_user/copy_from_user when one of parameters (kernel) was equal to 0
remove it and add properly annotated parameter

Signed-off-by: Marcin Ślusarz <marcin.slusarz@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>

Showing 1 changed file with 21 additions and 19 deletions Side-by-side Diff

sound/core/rawmidi.c
... ... @@ -911,7 +911,8 @@
911 911 }
912 912  
913 913 static long snd_rawmidi_kernel_read1(struct snd_rawmidi_substream *substream,
914   - unsigned char *buf, long count, int kernel)
  914 + unsigned char __user *userbuf,
  915 + unsigned char *kernelbuf, long count)
915 916 {
916 917 unsigned long flags;
917 918 long result = 0, count1;
918 919  
... ... @@ -924,11 +925,11 @@
924 925 spin_lock_irqsave(&runtime->lock, flags);
925 926 if (count1 > (int)runtime->avail)
926 927 count1 = runtime->avail;
927   - if (kernel) {
928   - memcpy(buf + result, runtime->buffer + runtime->appl_ptr, count1);
929   - } else {
  928 + if (kernelbuf)
  929 + memcpy(kernelbuf + result, runtime->buffer + runtime->appl_ptr, count1);
  930 + if (userbuf) {
930 931 spin_unlock_irqrestore(&runtime->lock, flags);
931   - if (copy_to_user((char __user *)buf + result,
  932 + if (copy_to_user(userbuf + result,
932 933 runtime->buffer + runtime->appl_ptr, count1)) {
933 934 return result > 0 ? result : -EFAULT;
934 935 }
... ... @@ -948,7 +949,7 @@
948 949 unsigned char *buf, long count)
949 950 {
950 951 snd_rawmidi_input_trigger(substream, 1);
951   - return snd_rawmidi_kernel_read1(substream, buf, count, 1);
  952 + return snd_rawmidi_kernel_read1(substream, NULL/*userbuf*/, buf, count);
952 953 }
953 954  
954 955 static ssize_t snd_rawmidi_read(struct file *file, char __user *buf, size_t count,
... ... @@ -989,8 +990,9 @@
989 990 }
990 991 spin_unlock_irq(&runtime->lock);
991 992 count1 = snd_rawmidi_kernel_read1(substream,
992   - (unsigned char __force *)buf,
993   - count, 0);
  993 + (unsigned char __user *)buf,
  994 + NULL/*kernelbuf*/,
  995 + count);
994 996 if (count1 < 0)
995 997 return result > 0 ? result : count1;
996 998 result += count1;
997 999  
... ... @@ -1131,13 +1133,15 @@
1131 1133 }
1132 1134  
1133 1135 static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream,
1134   - const unsigned char *buf, long count, int kernel)
  1136 + const unsigned char __user *userbuf,
  1137 + const unsigned char *kernelbuf,
  1138 + long count)
1135 1139 {
1136 1140 unsigned long flags;
1137 1141 long count1, result;
1138 1142 struct snd_rawmidi_runtime *runtime = substream->runtime;
1139 1143  
1140   - snd_assert(buf != NULL, return -EINVAL);
  1144 + snd_assert(kernelbuf != NULL || userbuf != NULL, return -EINVAL);
1141 1145 snd_assert(runtime->buffer != NULL, return -EINVAL);
1142 1146  
1143 1147 result = 0;
1144 1148  
... ... @@ -1154,12 +1158,13 @@
1154 1158 count1 = count;
1155 1159 if (count1 > (long)runtime->avail)
1156 1160 count1 = runtime->avail;
1157   - if (kernel) {
1158   - memcpy(runtime->buffer + runtime->appl_ptr, buf, count1);
1159   - } else {
  1161 + if (kernelbuf)
  1162 + memcpy(runtime->buffer + runtime->appl_ptr,
  1163 + kernelbuf + result, count1);
  1164 + else if (userbuf) {
1160 1165 spin_unlock_irqrestore(&runtime->lock, flags);
1161 1166 if (copy_from_user(runtime->buffer + runtime->appl_ptr,
1162   - (char __user *)buf, count1)) {
  1167 + userbuf + result, count1)) {
1163 1168 spin_lock_irqsave(&runtime->lock, flags);
1164 1169 result = result > 0 ? result : -EFAULT;
1165 1170 goto __end;
... ... @@ -1170,7 +1175,6 @@
1170 1175 runtime->appl_ptr %= runtime->buffer_size;
1171 1176 runtime->avail -= count1;
1172 1177 result += count1;
1173   - buf += count1;
1174 1178 count -= count1;
1175 1179 }
1176 1180 __end:
... ... @@ -1184,7 +1188,7 @@
1184 1188 long snd_rawmidi_kernel_write(struct snd_rawmidi_substream *substream,
1185 1189 const unsigned char *buf, long count)
1186 1190 {
1187   - return snd_rawmidi_kernel_write1(substream, buf, count, 1);
  1191 + return snd_rawmidi_kernel_write1(substream, NULL, buf, count);
1188 1192 }
1189 1193  
1190 1194 static ssize_t snd_rawmidi_write(struct file *file, const char __user *buf,
... ... @@ -1224,9 +1228,7 @@
1224 1228 spin_lock_irq(&runtime->lock);
1225 1229 }
1226 1230 spin_unlock_irq(&runtime->lock);
1227   - count1 = snd_rawmidi_kernel_write1(substream,
1228   - (unsigned char __force *)buf,
1229   - count, 0);
  1231 + count1 = snd_rawmidi_kernel_write1(substream, buf, NULL, count);
1230 1232 if (count1 < 0)
1231 1233 return result > 0 ? result : count1;
1232 1234 result += count1;