Commit 63623646 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: emu10k1: Fix missing __force annotation for user/kernel pointer cast

The cast between user-space and kernel-space needs an explicit __force
prefix, but it's missing in many places in emu10k1 driver code.

Spotted by sparse as a warning like:
  sound/pci/emu10k1/emufx.c:529:33: warning: cast removes address space of expression
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 0701492c
...@@ -526,7 +526,7 @@ static int snd_emu10k1_gpr_poke(struct snd_emu10k1 *emu, ...@@ -526,7 +526,7 @@ static int snd_emu10k1_gpr_poke(struct snd_emu10k1 *emu,
if (!test_bit(gpr, icode->gpr_valid)) if (!test_bit(gpr, icode->gpr_valid))
continue; continue;
if (in_kernel) if (in_kernel)
val = *(u32 *)&icode->gpr_map[gpr]; val = *(__force u32 *)&icode->gpr_map[gpr];
else if (get_user(val, &icode->gpr_map[gpr])) else if (get_user(val, &icode->gpr_map[gpr]))
return -EFAULT; return -EFAULT;
snd_emu10k1_ptr_write(emu, emu->gpr_base + gpr, 0, val); snd_emu10k1_ptr_write(emu, emu->gpr_base + gpr, 0, val);
...@@ -560,8 +560,8 @@ static int snd_emu10k1_tram_poke(struct snd_emu10k1 *emu, ...@@ -560,8 +560,8 @@ static int snd_emu10k1_tram_poke(struct snd_emu10k1 *emu,
if (!test_bit(tram, icode->tram_valid)) if (!test_bit(tram, icode->tram_valid))
continue; continue;
if (in_kernel) { if (in_kernel) {
val = *(u32 *)&icode->tram_data_map[tram]; val = *(__force u32 *)&icode->tram_data_map[tram];
addr = *(u32 *)&icode->tram_addr_map[tram]; addr = *(__force u32 *)&icode->tram_addr_map[tram];
} else { } else {
if (get_user(val, &icode->tram_data_map[tram]) || if (get_user(val, &icode->tram_data_map[tram]) ||
get_user(addr, &icode->tram_addr_map[tram])) get_user(addr, &icode->tram_addr_map[tram]))
...@@ -611,8 +611,8 @@ static int snd_emu10k1_code_poke(struct snd_emu10k1 *emu, ...@@ -611,8 +611,8 @@ static int snd_emu10k1_code_poke(struct snd_emu10k1 *emu,
if (!test_bit(pc / 2, icode->code_valid)) if (!test_bit(pc / 2, icode->code_valid))
continue; continue;
if (in_kernel) { if (in_kernel) {
lo = *(u32 *)&icode->code[pc + 0]; lo = *(__force u32 *)&icode->code[pc + 0];
hi = *(u32 *)&icode->code[pc + 1]; hi = *(__force u32 *)&icode->code[pc + 1];
} else { } else {
if (get_user(lo, &icode->code[pc + 0]) || if (get_user(lo, &icode->code[pc + 0]) ||
get_user(hi, &icode->code[pc + 1])) get_user(hi, &icode->code[pc + 1]))
...@@ -666,7 +666,7 @@ static unsigned int *copy_tlv(const unsigned int __user *_tlv, bool in_kernel) ...@@ -666,7 +666,7 @@ static unsigned int *copy_tlv(const unsigned int __user *_tlv, bool in_kernel)
if (!_tlv) if (!_tlv)
return NULL; return NULL;
if (in_kernel) if (in_kernel)
memcpy(data, (void *)_tlv, sizeof(data)); memcpy(data, (__force void *)_tlv, sizeof(data));
else if (copy_from_user(data, _tlv, sizeof(data))) else if (copy_from_user(data, _tlv, sizeof(data)))
return NULL; return NULL;
if (data[1] >= MAX_TLV_SIZE) if (data[1] >= MAX_TLV_SIZE)
...@@ -676,7 +676,7 @@ static unsigned int *copy_tlv(const unsigned int __user *_tlv, bool in_kernel) ...@@ -676,7 +676,7 @@ static unsigned int *copy_tlv(const unsigned int __user *_tlv, bool in_kernel)
return NULL; return NULL;
memcpy(tlv, data, sizeof(data)); memcpy(tlv, data, sizeof(data));
if (in_kernel) { if (in_kernel) {
memcpy(tlv + 2, (void *)(_tlv + 2), data[1]); memcpy(tlv + 2, (__force void *)(_tlv + 2), data[1]);
} else if (copy_from_user(tlv + 2, _tlv + 2, data[1])) { } else if (copy_from_user(tlv + 2, _tlv + 2, data[1])) {
kfree(tlv); kfree(tlv);
return NULL; return NULL;
...@@ -693,7 +693,7 @@ static int copy_gctl(struct snd_emu10k1 *emu, ...@@ -693,7 +693,7 @@ static int copy_gctl(struct snd_emu10k1 *emu,
if (emu->support_tlv) { if (emu->support_tlv) {
if (in_kernel) if (in_kernel)
memcpy(gctl, (void *)&_gctl[idx], sizeof(*gctl)); memcpy(gctl, (__force void *)&_gctl[idx], sizeof(*gctl));
else if (copy_from_user(gctl, &_gctl[idx], sizeof(*gctl))) else if (copy_from_user(gctl, &_gctl[idx], sizeof(*gctl)))
return -EFAULT; return -EFAULT;
return 0; return 0;
...@@ -701,7 +701,7 @@ static int copy_gctl(struct snd_emu10k1 *emu, ...@@ -701,7 +701,7 @@ static int copy_gctl(struct snd_emu10k1 *emu,
octl = (struct snd_emu10k1_fx8010_control_old_gpr __user *)_gctl; octl = (struct snd_emu10k1_fx8010_control_old_gpr __user *)_gctl;
if (in_kernel) if (in_kernel)
memcpy(gctl, (void *)&octl[idx], sizeof(*octl)); memcpy(gctl, (__force void *)&octl[idx], sizeof(*octl));
else if (copy_from_user(gctl, &octl[idx], sizeof(*octl))) else if (copy_from_user(gctl, &octl[idx], sizeof(*octl)))
return -EFAULT; return -EFAULT;
gctl->tlv = NULL; gctl->tlv = NULL;
...@@ -735,7 +735,7 @@ static int snd_emu10k1_verify_controls(struct snd_emu10k1 *emu, ...@@ -735,7 +735,7 @@ static int snd_emu10k1_verify_controls(struct snd_emu10k1 *emu,
for (i = 0, _id = icode->gpr_del_controls; for (i = 0, _id = icode->gpr_del_controls;
i < icode->gpr_del_control_count; i++, _id++) { i < icode->gpr_del_control_count; i++, _id++) {
if (in_kernel) if (in_kernel)
id = *(struct snd_ctl_elem_id *)_id; id = *(__force struct snd_ctl_elem_id *)_id;
else if (copy_from_user(&id, _id, sizeof(id))) else if (copy_from_user(&id, _id, sizeof(id)))
return -EFAULT; return -EFAULT;
if (snd_emu10k1_look_for_ctl(emu, &id) == NULL) if (snd_emu10k1_look_for_ctl(emu, &id) == NULL)
...@@ -833,7 +833,7 @@ static int snd_emu10k1_add_controls(struct snd_emu10k1 *emu, ...@@ -833,7 +833,7 @@ static int snd_emu10k1_add_controls(struct snd_emu10k1 *emu,
knew.device = gctl->id.device; knew.device = gctl->id.device;
knew.subdevice = gctl->id.subdevice; knew.subdevice = gctl->id.subdevice;
knew.info = snd_emu10k1_gpr_ctl_info; knew.info = snd_emu10k1_gpr_ctl_info;
knew.tlv.p = copy_tlv(gctl->tlv, in_kernel); knew.tlv.p = copy_tlv((__force const unsigned int __user *)gctl->tlv, in_kernel);
if (knew.tlv.p) if (knew.tlv.p)
knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE | knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
SNDRV_CTL_ELEM_ACCESS_TLV_READ; SNDRV_CTL_ELEM_ACCESS_TLV_READ;
...@@ -897,7 +897,7 @@ static int snd_emu10k1_del_controls(struct snd_emu10k1 *emu, ...@@ -897,7 +897,7 @@ static int snd_emu10k1_del_controls(struct snd_emu10k1 *emu,
for (i = 0, _id = icode->gpr_del_controls; for (i = 0, _id = icode->gpr_del_controls;
i < icode->gpr_del_control_count; i++, _id++) { i < icode->gpr_del_control_count; i++, _id++) {
if (in_kernel) if (in_kernel)
id = *(struct snd_ctl_elem_id *)_id; id = *(__force struct snd_ctl_elem_id *)_id;
else if (copy_from_user(&id, _id, sizeof(id))) else if (copy_from_user(&id, _id, sizeof(id)))
return -EFAULT; return -EFAULT;
down_write(&card->controls_rwsem); down_write(&card->controls_rwsem);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment