Ignore:
Timestamp:
Mar 18, 2021, 8:57:36 PM (4 years ago)
Author:
David Azarewicz
Message:

Merge changes from Paul's uniaud32next branch.

Location:
GPL/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • GPL/trunk

  • GPL/trunk/alsa-kernel/pci/emu10k1/emufx.c

    r598 r679  
     1// SPDX-License-Identifier: GPL-2.0-or-later
    12/*
    23 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
     
    1213 *  TODO:
    1314 *    --
    14  *
    15  *   This program is free software; you can redistribute it and/or modify
    16  *   it under the terms of the GNU General Public License as published by
    17  *   the Free Software Foundation; either version 2 of the License, or
    18  *   (at your option) any later version.
    19  *
    20  *   This program is distributed in the hope that it will be useful,
    21  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    22  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    23  *   GNU General Public License for more details.
    24  *
    25  *   You should have received a copy of the GNU General Public License
    26  *   along with this program; if not, write to the Free Software
    27  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    28  *
    2915 */
    3016
     
    3723#include <linux/mutex.h>
    3824#include <linux/moduleparam.h>
     25#include <linux/nospec.h>
    3926
    4027#include <sound/core.h>
     
    5946/*
    6047 *  Tables
    61  */
    62 
    63 static char *fxbuses[16] = {
     48 */ 
     49
     50static const char * const fxbuses[16] = {
    6451        /* 0x00 */ "PCM Left",
    6552        /* 0x01 */ "PCM Right",
     
    8067};
    8168
    82 static char *creative_ins[16] = {
     69static const char * const creative_ins[16] = {
    8370        /* 0x00 */ "AC97 Left",
    8471        /* 0x01 */ "AC97 Right",
     
    9986};
    10087
    101 static char *audigy_ins[16] = {
     88static const char * const audigy_ins[16] = {
    10289        /* 0x00 */ "AC97 Left",
    10390        /* 0x01 */ "AC97 Right",
     
    118105};
    119106
    120 static char *creative_outs[32] = {
     107static const char * const creative_outs[32] = {
    121108        /* 0x00 */ "AC97 Left",
    122109        /* 0x01 */ "AC97 Right",
     
    153140};
    154141
    155 static char *audigy_outs[32] = {
     142static const char * const audigy_outs[32] = {
    156143        /* 0x00 */ "Digital Front Left",
    157144        /* 0x01 */ "Digital Front Right",
     
    172159        /* 0x10 */ "AC97 Front Left",
    173160        /* 0x11 */ "AC97 Front Right",
    174         /* 0x12 */ "ADC Caputre Left",
     161        /* 0x12 */ "ADC Capture Left",
    175162        /* 0x13 */ "ADC Capture Right",
    176163        /* 0x14 */ NULL,
     
    305292static const DECLARE_TLV_DB_LINEAR(snd_emu10k1_db_linear, TLV_DB_GAIN_MUTE, 0);
    306293
     294/* EMU10K1 bass/treble db gain */
     295static const DECLARE_TLV_DB_SCALE(snd_emu10k1_bass_treble_db_scale, -1200, 60, 0);
     296
    307297static const u32 onoff_table[2] = {
    308298        0x00000000, 0x00000001
    309299};
    310 
    311 /*
    312  */
    313 
    314 static inline mm_segment_t snd_enter_user(void)
    315 {
    316         mm_segment_t fs = get_fs();
    317         set_fs(get_ds());
    318         return fs;
    319 }
    320 
    321 static inline void snd_leave_user(mm_segment_t fs)
    322 {
    323         set_fs(fs);
    324 }
    325300
    326301/*
     
    435410                                            unsigned char gpr_running,
    436411                                            void *private_data,
    437                                             struct snd_emu10k1_fx8010_irq **r_irq)
    438 {
    439         struct snd_emu10k1_fx8010_irq *irq;
     412                                            struct snd_emu10k1_fx8010_irq *irq)
     413{
    440414        unsigned long flags;
    441415       
    442         irq = kmalloc(sizeof(*irq), GFP_ATOMIC);
    443         if (irq == NULL)
    444                 return -ENOMEM;
    445416        irq->handler = handler;
    446417        irq->gpr_running = gpr_running;
     
    457428        }
    458429        spin_unlock_irqrestore(&emu->fx8010.irq_lock, flags);
    459         if (r_irq)
    460                 *r_irq = irq;
    461430        return 0;
    462431}
     
    482451        }
    483452        spin_unlock_irqrestore(&emu->fx8010.irq_lock, flags);
    484         kfree(irq);
    485453        return 0;
    486454}
     
    497465        if (snd_BUG_ON(*ptr >= 512))
    498466                return;
    499         code = (u_int32_t __force *)icode->code + (*ptr) * 2;
     467        code = icode->code + (*ptr) * 2;
    500468        set_bit(*ptr, icode->code_valid);
    501469        code[0] = ((x & 0x3ff) << 10) | (y & 0x3ff);
     
    514482        if (snd_BUG_ON(*ptr >= 1024))
    515483                return;
    516         code = (u_int32_t __force *)icode->code + (*ptr) * 2;
     484        code = icode->code + (*ptr) * 2;
    517485        set_bit(*ptr, icode->code_valid);
    518486        code[0] = ((x & 0x7ff) << 12) | (y & 0x7ff);
     
    537505
    538506static int snd_emu10k1_gpr_poke(struct snd_emu10k1 *emu,
    539                                 struct snd_emu10k1_fx8010_code *icode)
     507                                struct snd_emu10k1_fx8010_code *icode,
     508                                bool in_kernel)
    540509{
    541510        int gpr;
     
    545514                if (!test_bit(gpr, icode->gpr_valid))
    546515                        continue;
    547                 if (get_user(val, &icode->gpr_map[gpr]))
     516                if (in_kernel)
     517                        val = icode->gpr_map[gpr];
     518                else if (get_user(val, (__user u32 *)&icode->gpr_map[gpr]))
    548519                        return -EFAULT;
    549520                snd_emu10k1_ptr_write(emu, emu->gpr_base + gpr, 0, val);
     
    561532                set_bit(gpr, icode->gpr_valid);
    562533                val = snd_emu10k1_ptr_read(emu, emu->gpr_base + gpr, 0);
    563                 if (put_user(val, &icode->gpr_map[gpr]))
     534                if (put_user(val, (__user u32 *)&icode->gpr_map[gpr]))
    564535                        return -EFAULT;
    565536        }
     
    568539
    569540static int snd_emu10k1_tram_poke(struct snd_emu10k1 *emu,
    570                                  struct snd_emu10k1_fx8010_code *icode)
     541                                 struct snd_emu10k1_fx8010_code *icode,
     542                                 bool in_kernel)
    571543{
    572544        int tram;
     
    576548                if (!test_bit(tram, icode->tram_valid))
    577549                        continue;
    578                 if (get_user(val, &icode->tram_data_map[tram]) ||
    579                     get_user(addr, &icode->tram_addr_map[tram]))
    580                         return -EFAULT;
     550                if (in_kernel) {
     551                        val = icode->tram_data_map[tram];
     552                        addr = icode->tram_addr_map[tram];
     553                } else {
     554                        if (get_user(val, (__user __u32 *)&icode->tram_data_map[tram]) ||
     555                            get_user(addr, (__user __u32 *)&icode->tram_addr_map[tram]))
     556                                return -EFAULT;
     557                }
    581558                snd_emu10k1_ptr_write(emu, TANKMEMDATAREGBASE + tram, 0, val);
    582559                if (!emu->audigy) {
     
    606583                        addr |= snd_emu10k1_ptr_read(emu, A_TANKMEMCTLREGBASE + tram, 0) << 20;
    607584                }
    608                 if (put_user(val, &icode->tram_data_map[tram]) ||
    609                     put_user(addr, &icode->tram_addr_map[tram]))
     585                if (put_user(val, (__user u32 *)&icode->tram_data_map[tram]) ||
     586                    put_user(addr, (__user u32 *)&icode->tram_addr_map[tram]))
    610587                        return -EFAULT;
    611588        }
     
    614591
    615592static int snd_emu10k1_code_poke(struct snd_emu10k1 *emu,
    616                                  struct snd_emu10k1_fx8010_code *icode)
     593                                 struct snd_emu10k1_fx8010_code *icode,
     594                                 bool in_kernel)
    617595{
    618596        u32 pc, lo, hi;
     
    621599                if (!test_bit(pc / 2, icode->code_valid))
    622600                        continue;
    623                 if (get_user(lo, &icode->code[pc + 0]) ||
    624                     get_user(hi, &icode->code[pc + 1]))
    625                         return -EFAULT;
     601                if (in_kernel) {
     602                        lo = icode->code[pc + 0];
     603                        hi = icode->code[pc + 1];
     604                } else {
     605                        if (get_user(lo, (__user u32 *)&icode->code[pc + 0]) ||
     606                            get_user(hi, (__user u32 *)&icode->code[pc + 1]))
     607                                return -EFAULT;
     608                }
    626609                snd_emu10k1_efx_write(emu, pc + 0, lo);
    627610                snd_emu10k1_efx_write(emu, pc + 1, hi);
     
    638621        for (pc = 0; pc < (emu->audigy ? 2*1024 : 2*512); pc += 2) {
    639622                set_bit(pc / 2, icode->code_valid);
    640                 if (put_user(snd_emu10k1_efx_read(emu, pc + 0), &icode->code[pc + 0]))
     623                if (put_user(snd_emu10k1_efx_read(emu, pc + 0),
     624                             (__user u32 *)&icode->code[pc + 0]))
    641625                        return -EFAULT;
    642                 if (put_user(snd_emu10k1_efx_read(emu, pc + 1), &icode->code[pc + 1]))
     626                if (put_user(snd_emu10k1_efx_read(emu, pc + 1),
     627                             (__user u32 *)&icode->code[pc + 1]))
    643628                        return -EFAULT;
    644629        }
     
    647632
    648633static struct snd_emu10k1_fx8010_ctl *
    649 snd_emu10k1_look_for_ctl(struct snd_emu10k1 *emu, struct snd_ctl_elem_id *id)
    650 {
     634snd_emu10k1_look_for_ctl(struct snd_emu10k1 *emu,
     635                         struct emu10k1_ctl_elem_id *_id)
     636{
     637        struct snd_ctl_elem_id *id = (struct snd_ctl_elem_id *)_id;
    651638        struct snd_emu10k1_fx8010_ctl *ctl;
    652639        struct snd_kcontrol *kcontrol;
     
    664651#define MAX_TLV_SIZE    256
    665652
    666 static unsigned int *copy_tlv(const unsigned int __user *_tlv)
     653static unsigned int *copy_tlv(const unsigned int __user *_tlv, bool in_kernel)
    667654{
    668655        unsigned int data[2];
     
    671658        if (!_tlv)
    672659                return NULL;
    673         if (copy_from_user(data, _tlv, sizeof(data)))
     660        if (in_kernel)
     661                memcpy(data, (__force void *)_tlv, sizeof(data));
     662        else if (copy_from_user(data, _tlv, sizeof(data)))
    674663                return NULL;
    675664        if (data[1] >= MAX_TLV_SIZE)
     
    679668                return NULL;
    680669        memcpy(tlv, data, sizeof(data));
    681         if (copy_from_user(tlv + 2, _tlv + 2, data[1])) {
     670        if (in_kernel) {
     671                memcpy(tlv + 2, (__force void *)(_tlv + 2),  data[1]);
     672        } else if (copy_from_user(tlv + 2, _tlv + 2, data[1])) {
    682673                kfree(tlv);
    683674                return NULL;
     
    687678
    688679static int copy_gctl(struct snd_emu10k1 *emu,
    689                      struct snd_emu10k1_fx8010_control_gpr *gctl,
    690                      struct snd_emu10k1_fx8010_control_gpr __user *_gctl,
     680                     struct snd_emu10k1_fx8010_control_gpr *dst,
     681                     struct snd_emu10k1_fx8010_control_gpr *src,
     682                     int idx, bool in_kernel)
     683{
     684        struct snd_emu10k1_fx8010_control_gpr __user *_src;
     685        struct snd_emu10k1_fx8010_control_old_gpr *octl;
     686        struct snd_emu10k1_fx8010_control_old_gpr __user *_octl;
     687
     688        _src = (struct snd_emu10k1_fx8010_control_gpr __user *)src;
     689        if (emu->support_tlv) {
     690                if (in_kernel)
     691                        *dst = src[idx];
     692                else if (copy_from_user(dst, &_src[idx], sizeof(*src)))
     693                        return -EFAULT;
     694                return 0;
     695        }
     696
     697        octl = (struct snd_emu10k1_fx8010_control_old_gpr *)src;
     698        _octl = (struct snd_emu10k1_fx8010_control_old_gpr __user *)octl;
     699        if (in_kernel)
     700                memcpy(dst, &octl[idx], sizeof(*octl));
     701        else if (copy_from_user(dst, &_octl[idx], sizeof(*octl)))
     702                return -EFAULT;
     703        dst->tlv = NULL;
     704        return 0;
     705}
     706
     707static int copy_gctl_to_user(struct snd_emu10k1 *emu,
     708                     struct snd_emu10k1_fx8010_control_gpr *dst,
     709                     struct snd_emu10k1_fx8010_control_gpr *src,
    691710                     int idx)
    692711{
     712        struct snd_emu10k1_fx8010_control_gpr __user *_dst;
    693713        struct snd_emu10k1_fx8010_control_old_gpr __user *octl;
    694714
     715        _dst = (struct snd_emu10k1_fx8010_control_gpr __user *)dst;
    695716        if (emu->support_tlv)
    696                 return copy_from_user(gctl, &_gctl[idx], sizeof(*gctl));
    697         octl = (struct snd_emu10k1_fx8010_control_old_gpr __user *)_gctl;
    698         if (copy_from_user(gctl, &octl[idx], sizeof(*octl)))
     717                return copy_to_user(&_dst[idx], src, sizeof(*src));
     718       
     719        octl = (struct snd_emu10k1_fx8010_control_old_gpr __user *)dst;
     720        return copy_to_user(&octl[idx], src, sizeof(*octl));
     721}
     722
     723static int copy_ctl_elem_id(const struct emu10k1_ctl_elem_id *list, int i,
     724                            struct emu10k1_ctl_elem_id *ret, bool in_kernel)
     725{
     726        struct emu10k1_ctl_elem_id __user *_id =
     727                (struct emu10k1_ctl_elem_id __user *)&list[i];
     728
     729        if (in_kernel)
     730                *ret = list[i];
     731        else if (copy_from_user(ret, _id, sizeof(*ret)))
    699732                return -EFAULT;
    700         gctl->tlv = NULL;
    701733        return 0;
    702734}
    703735
    704 static int copy_gctl_to_user(struct snd_emu10k1 *emu,
    705                      struct snd_emu10k1_fx8010_control_gpr __user *_gctl,
    706                      struct snd_emu10k1_fx8010_control_gpr *gctl,
    707                      int idx)
    708 {
    709         struct snd_emu10k1_fx8010_control_old_gpr __user *octl;
    710 
    711         if (emu->support_tlv)
    712                 return copy_to_user(&_gctl[idx], gctl, sizeof(*gctl));
    713        
    714         octl = (struct snd_emu10k1_fx8010_control_old_gpr __user *)_gctl;
    715         return copy_to_user(&octl[idx], gctl, sizeof(*octl));
    716 }
    717 
    718736static int snd_emu10k1_verify_controls(struct snd_emu10k1 *emu,
    719                                        struct snd_emu10k1_fx8010_code *icode)
     737                                       struct snd_emu10k1_fx8010_code *icode,
     738                                       bool in_kernel)
    720739{
    721740        unsigned int i;
    722         struct snd_ctl_elem_id __user *_id;
    723         struct snd_ctl_elem_id id;
     741        struct emu10k1_ctl_elem_id id;
    724742        struct snd_emu10k1_fx8010_control_gpr *gctl;
     743        struct snd_ctl_elem_id *gctl_id;
    725744        int err;
    726745       
    727         for (i = 0, _id = icode->gpr_del_controls;
    728              i < icode->gpr_del_control_count; i++, _id++) {
    729                 if (copy_from_user(&id, _id, sizeof(id)))
    730                         return -EFAULT;
     746        for (i = 0; i < icode->gpr_del_control_count; i++) {
     747                err = copy_ctl_elem_id(icode->gpr_del_controls, i, &id,
     748                                       in_kernel);
     749                if (err < 0)
     750                        return err;
    731751                if (snd_emu10k1_look_for_ctl(emu, &id) == NULL)
    732752                        return -ENOENT;
     
    737757        err = 0;
    738758        for (i = 0; i < icode->gpr_add_control_count; i++) {
    739                 if (copy_gctl(emu, gctl, icode->gpr_add_controls, i)) {
     759                if (copy_gctl(emu, gctl, icode->gpr_add_controls, i,
     760                              in_kernel)) {
    740761                        err = -EFAULT;
    741762                        goto __error;
     
    743764                if (snd_emu10k1_look_for_ctl(emu, &gctl->id))
    744765                        continue;
     766                gctl_id = (struct snd_ctl_elem_id *)&gctl->id;
    745767                down_read(&emu->card->controls_rwsem);
    746                 if (snd_ctl_find_id(emu->card, &gctl->id) != NULL) {
     768                if (snd_ctl_find_id(emu->card, gctl_id)) {
    747769                        up_read(&emu->card->controls_rwsem);
    748770                        err = -EEXIST;
     
    750772                }
    751773                up_read(&emu->card->controls_rwsem);
    752                 if (gctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER &&
    753                     gctl->id.iface != SNDRV_CTL_ELEM_IFACE_PCM) {
     774                if (gctl_id->iface != SNDRV_CTL_ELEM_IFACE_MIXER &&
     775                    gctl_id->iface != SNDRV_CTL_ELEM_IFACE_PCM) {
    754776                        err = -EINVAL;
    755777                        goto __error;
     
    758780        for (i = 0; i < icode->gpr_list_control_count; i++) {
    759781                /* FIXME: we need to check the WRITE access */
    760                 if (copy_gctl(emu, gctl, icode->gpr_list_controls, i)) {
     782                if (copy_gctl(emu, gctl, icode->gpr_list_controls, i,
     783                              in_kernel)) {
    761784                        err = -EFAULT;
    762785                        goto __error;
     
    776799        list_del(&ctl->list);
    777800        kfree(ctl);
    778         if (kctl->tlv.p)
    779                 kfree(kctl->tlv.p);
     801        kfree(kctl->tlv.p);
    780802}
    781803
    782804static int snd_emu10k1_add_controls(struct snd_emu10k1 *emu,
    783                                     struct snd_emu10k1_fx8010_code *icode)
     805                                    struct snd_emu10k1_fx8010_code *icode,
     806                                    bool in_kernel)
    784807{
    785808        unsigned int i, j;
    786809        struct snd_emu10k1_fx8010_control_gpr *gctl;
     810        struct snd_ctl_elem_id *gctl_id;
    787811        struct snd_emu10k1_fx8010_ctl *ctl, *nctl;
    788812        struct snd_kcontrol_new knew;
     
    800824
    801825        for (i = 0; i < icode->gpr_add_control_count; i++) {
    802                 if (copy_gctl(emu, gctl, icode->gpr_add_controls, i)) {
     826                if (copy_gctl(emu, gctl, icode->gpr_add_controls, i,
     827                              in_kernel)) {
    803828                        err = -EFAULT;
    804829                        goto __error;
    805830                }
    806                 if (gctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER &&
    807                     gctl->id.iface != SNDRV_CTL_ELEM_IFACE_PCM) {
     831                gctl_id = (struct snd_ctl_elem_id *)&gctl->id;
     832                if (gctl_id->iface != SNDRV_CTL_ELEM_IFACE_MIXER &&
     833                    gctl_id->iface != SNDRV_CTL_ELEM_IFACE_PCM) {
    808834                        err = -EINVAL;
    809835                        goto __error;
    810836                }
    811                 if (! gctl->id.name[0]) {
     837                if (!*gctl_id->name) {
    812838                        err = -EINVAL;
    813839                        goto __error;
     
    815841                ctl = snd_emu10k1_look_for_ctl(emu, &gctl->id);
    816842                memset(&knew, 0, sizeof(knew));
    817                 knew.iface = gctl->id.iface;
    818                 knew.name = gctl->id.name;
    819                 knew.index = gctl->id.index;
    820                 knew.device = gctl->id.device;
    821                 knew.subdevice = gctl->id.subdevice;
     843                knew.iface = gctl_id->iface;
     844                knew.name = gctl_id->name;
     845                knew.index = gctl_id->index;
     846                knew.device = gctl_id->device;
     847                knew.subdevice = gctl_id->subdevice;
    822848                knew.info = snd_emu10k1_gpr_ctl_info;
    823                 knew.tlv.p = copy_tlv(gctl->tlv);
     849                knew.tlv.p = copy_tlv((const unsigned int __user *)gctl->tlv, in_kernel);
    824850                if (knew.tlv.p)
    825851                        knew.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
     
    873899
    874900static int snd_emu10k1_del_controls(struct snd_emu10k1 *emu,
    875                                     struct snd_emu10k1_fx8010_code *icode)
     901                                    struct snd_emu10k1_fx8010_code *icode,
     902                                    bool in_kernel)
    876903{
    877904        unsigned int i;
    878         struct snd_ctl_elem_id id;
    879         struct snd_ctl_elem_id __user *_id;
     905        struct emu10k1_ctl_elem_id id;
    880906        struct snd_emu10k1_fx8010_ctl *ctl;
    881907        struct snd_card *card = emu->card;
    882        
    883         for (i = 0, _id = icode->gpr_del_controls;
    884              i < icode->gpr_del_control_count; i++, _id++) {
    885                 if (copy_from_user(&id, _id, sizeof(id)))
    886                         return -EFAULT;
     908        int err;
     909       
     910        for (i = 0; i < icode->gpr_del_control_count; i++) {
     911                err = copy_ctl_elem_id(icode->gpr_del_controls, i, &id,
     912                                       in_kernel);
     913                if (err < 0)
     914                        return err;
    887915                down_write(&card->controls_rwsem);
    888916                ctl = snd_emu10k1_look_for_ctl(emu, &id);
     
    913941                        memset(gctl, 0, sizeof(*gctl));
    914942                        id = &ctl->kcontrol->id;
    915                         gctl->id.iface = id->iface;
     943                        gctl->id.iface = (__force int)id->iface;
    916944                        strlcpy(gctl->id.name, id->name, sizeof(gctl->id.name));
    917945                        gctl->id.index = id->index;
     
    941969
    942970static int snd_emu10k1_icode_poke(struct snd_emu10k1 *emu,
    943                                   struct snd_emu10k1_fx8010_code *icode)
     971                                  struct snd_emu10k1_fx8010_code *icode,
     972                                  bool in_kernel)
    944973{
    945974        int err = 0;
    946975
    947976        mutex_lock(&emu->fx8010.lock);
    948         if ((err = snd_emu10k1_verify_controls(emu, icode)) < 0)
     977        err = snd_emu10k1_verify_controls(emu, icode, in_kernel);
     978        if (err < 0)
    949979                goto __error;
    950980        strlcpy(emu->fx8010.name, icode->name, sizeof(emu->fx8010.name));
     
    956986                snd_emu10k1_ptr_write(emu, DBG, 0, emu->fx8010.dbg | EMU10K1_DBG_SINGLE_STEP);
    957987        /* ok, do the main job */
    958         if ((err = snd_emu10k1_del_controls(emu, icode)) < 0 ||
    959             (err = snd_emu10k1_gpr_poke(emu, icode)) < 0 ||
    960             (err = snd_emu10k1_tram_poke(emu, icode)) < 0 ||
    961             (err = snd_emu10k1_code_poke(emu, icode)) < 0 ||
    962             (err = snd_emu10k1_add_controls(emu, icode)) < 0)
     988        err = snd_emu10k1_del_controls(emu, icode, in_kernel);
     989        if (err < 0)
     990                goto __error;
     991        err = snd_emu10k1_gpr_poke(emu, icode, in_kernel);
     992        if (err < 0)
     993                goto __error;
     994        err = snd_emu10k1_tram_poke(emu, icode, in_kernel);
     995        if (err < 0)
     996                goto __error;
     997        err = snd_emu10k1_code_poke(emu, icode, in_kernel);
     998        if (err < 0)
     999                goto __error;
     1000        err = snd_emu10k1_add_controls(emu, icode, in_kernel);
     1001        if (err < 0)
    9631002                goto __error;
    9641003        /* start FX processor when the DSP code is updated */
     
    10001039        if (ipcm->substream >= EMU10K1_FX8010_PCM_COUNT)
    10011040                return -EINVAL;
     1041        ipcm->substream = array_index_nospec(ipcm->substream,
     1042                                             EMU10K1_FX8010_PCM_COUNT);
    10021043        if (ipcm->channels > 32)
    10031044                return -EINVAL;
     
    10461087        if (ipcm->substream >= EMU10K1_FX8010_PCM_COUNT)
    10471088                return -EINVAL;
     1089        ipcm->substream = array_index_nospec(ipcm->substream,
     1090                                             EMU10K1_FX8010_PCM_COUNT);
    10481091        pcm = &emu->fx8010.pcm[ipcm->substream];
    10491092        mutex_lock(&emu->fx8010.lock);
     
    10721115#define SND_EMU10K1_CAPTURE_CHANNELS    4
    10731116
    1074 static void __devinit
     1117static void
    10751118snd_emu10k1_init_mono_control(struct snd_emu10k1_fx8010_control_gpr *ctl,
    10761119                              const char *name, int gpr, int defval)
    10771120{
    1078         ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     1121        ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER;
    10791122        strcpy(ctl->id.name, name);
    10801123        ctl->vcount = ctl->count = 1;
     
    10931136}
    10941137
    1095 static void __devinit
     1138static void
    10961139snd_emu10k1_init_stereo_control(struct snd_emu10k1_fx8010_control_gpr *ctl,
    10971140                                const char *name, int gpr, int defval)
    10981141{
    1099         ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     1142        ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER;
    11001143        strcpy(ctl->id.name, name);
    11011144        ctl->vcount = ctl->count = 2;
     
    11151158}
    11161159
    1117 static void __devinit
     1160static void
    11181161snd_emu10k1_init_mono_onoff_control(struct snd_emu10k1_fx8010_control_gpr *ctl,
    11191162                                    const char *name, int gpr, int defval)
    11201163{
    1121         ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     1164        ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER;
    11221165        strcpy(ctl->id.name, name);
    11231166        ctl->vcount = ctl->count = 1;
     
    11281171}
    11291172
    1130 static void __devinit
     1173static void
    11311174snd_emu10k1_init_stereo_onoff_control(struct snd_emu10k1_fx8010_control_gpr *ctl,
    11321175                                      const char *name, int gpr, int defval)
    11331176{
    1134         ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     1177        ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER;
    11351178        strcpy(ctl->id.name, name);
    11361179        ctl->vcount = ctl->count = 2;
     
    11671210 */
    11681211
    1169 static int __devinit _snd_emu10k1_audigy_init_efx(struct snd_emu10k1 *emu)
     1212static int _snd_emu10k1_audigy_init_efx(struct snd_emu10k1 *emu)
    11701213{
    11711214        int err, i, z, gpr, nctl;
     
    11791222        struct snd_emu10k1_fx8010_control_gpr *controls = NULL, *ctl;
    11801223        u32 *gpr_map;
    1181         mm_segment_t seg;
    1182 
    1183         if ((icode = kzalloc(sizeof(*icode), GFP_KERNEL)) == NULL ||
    1184             (icode->gpr_map = (u_int32_t __user *)
    1185              kcalloc(512 + 256 + 256 + 2 * 1024, sizeof(u_int32_t),
    1186                      GFP_KERNEL)) == NULL ||
    1187             (controls = kcalloc(SND_EMU10K1_GPR_CONTROLS,
    1188                                 sizeof(*controls), GFP_KERNEL)) == NULL) {
    1189                 err = -ENOMEM;
    1190                 goto __err;
    1191         }
    1192         gpr_map = (u32 __force *)icode->gpr_map;
     1224
     1225        err = -ENOMEM;
     1226        icode = kzalloc(sizeof(*icode), GFP_KERNEL);
     1227        if (!icode)
     1228                return err;
     1229
     1230        icode->gpr_map = kcalloc(512 + 256 + 256 + 2 * 1024,
     1231                                 sizeof(u_int32_t), GFP_KERNEL);
     1232        if (!icode->gpr_map)
     1233                goto __err_gpr;
     1234        controls = kcalloc(SND_EMU10K1_GPR_CONTROLS,
     1235                           sizeof(*controls), GFP_KERNEL);
     1236        if (!controls)
     1237                goto __err_ctrls;
     1238
     1239        gpr_map = icode->gpr_map;
    11931240
    11941241        icode->tram_data_map = icode->gpr_map + 512;
     
    12771324        snd_emu10k1_init_stereo_control(&controls[nctl++], "Synth Capture Volume", gpr, 0);
    12781325        gpr += 2;
    1279 
     1326     
    12801327        /*
    12811328         * inputs
     
    13531400                                        gpr, 0);
    13541401        gpr += 2;
    1355 
     1402       
    13561403        /* Philips ADC Playback Volume */
    13571404        A_ADD_VOLUME_IN(stereo_mix, gpr, A_EXTIN_ADC_L);
     
    14451492
    14461493        ctl = &controls[nctl + 0];
    1447         ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     1494        ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER;
    14481495        strcpy(ctl->id.name, "Tone Control - Bass");
    14491496        ctl->vcount = 2;
     
    14541501        ctl->translation = EMU10K1_GPR_TRANSLATION_BASS;
    14551502        ctl = &controls[nctl + 1];
    1456         ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     1503        ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER;
    14571504        strcpy(ctl->id.name, "Tone Control - Treble");
    14581505        ctl->vcount = 2;
     
    15411588        if (emu->card_capabilities->emu_model) {
    15421589                /* EMU1010 Outputs from PCM Front, Rear, Center, LFE, Side */
    1543                 snd_printk(KERN_INFO "EMU outputs on\n");
     1590                dev_info(emu->card->dev, "EMU outputs on\n");
    15441591                for (z = 0; z < 8; z++) {
    15451592                        if (emu->card_capabilities->ca0108_chip) {
     
    15511598        }
    15521599
    1553         /* IEC958 Optical Raw Playback Switch */
     1600        /* IEC958 Optical Raw Playback Switch */ 
    15541601        gpr_map[gpr++] = 0;
    15551602        gpr_map[gpr++] = 0x1008;
     
    15651612                if ((z==1) && (emu->card_capabilities->spdif_bug)) {
    15661613                        /* Due to a SPDIF output bug on some Audigy cards, this code delays the Right channel by 1 sample */
    1567                         snd_printk(KERN_INFO "Installing spdif_bug patch: %s\n", emu->card_capabilities->name);
     1614                        dev_info(emu->card->dev,
     1615                                 "Installing spdif_bug patch: %s\n",
     1616                                 emu->card_capabilities->name);
    15681617                        A_OP(icode, &ptr, iACC3, A_EXTOUT(A_EXTOUT_FRONT_L + z), A_GPR(gpr - 3), A_C_00000000, A_C_00000000);
    15691618                        A_OP(icode, &ptr, iACC3, A_GPR(gpr - 3), A_GPR(tmp + 0), A_GPR(tmp + 1), A_C_00000000);
     
    15891638        if (emu->card_capabilities->emu_model) {
    15901639                if (emu->card_capabilities->ca0108_chip) {
    1591                         snd_printk(KERN_INFO "EMU2 inputs on\n");
     1640                        dev_info(emu->card->dev, "EMU2 inputs on\n");
    15921641                        for (z = 0; z < 0x10; z++) {
    1593                                 snd_emu10k1_audigy_dsp_convert_32_to_2x16( icode, &ptr, tmp,
     1642                                snd_emu10k1_audigy_dsp_convert_32_to_2x16( icode, &ptr, tmp, 
    15941643                                                                        bit_shifter16,
    15951644                                                                        A3_EMU32IN(z),
     
    15971646                        }
    15981647                } else {
    1599                         snd_printk(KERN_INFO "EMU inputs on\n");
     1648                        dev_info(emu->card->dev, "EMU inputs on\n");
    16001649                        /* Capture 16 (originally 8) channels of S32_LE sound */
    16011650
    16021651                        /*
    1603                         printk(KERN_DEBUG "emufx.c: gpr=0x%x, tmp=0x%x\n",
     1652                        dev_dbg(emu->card->dev, "emufx.c: gpr=0x%x, tmp=0x%x\n",
    16041653                               gpr, tmp);
    16051654                        */
     
    17321781                A_OP(icode, &ptr, 0x0f, 0xc0, 0xc0, 0xcf, 0xc0);
    17331782
    1734         seg = snd_enter_user();
    17351783        icode->gpr_add_control_count = nctl;
    1736         icode->gpr_add_controls = (struct snd_emu10k1_fx8010_control_gpr __user *)controls;
     1784        icode->gpr_add_controls = controls;
    17371785        emu->support_tlv = 1; /* support TLV */
    1738         err = snd_emu10k1_icode_poke(emu, icode);
     1786        err = snd_emu10k1_icode_poke(emu, icode, true);
    17391787        emu->support_tlv = 0; /* clear again */
    1740         snd_leave_user(seg);
    1741 
    1742  __err:
     1788
     1789__err:
    17431790        kfree(controls);
    1744         if (icode != NULL) {
    1745                 kfree((void __force *)icode->gpr_map);
    1746                 kfree(icode);
    1747         }
     1791__err_ctrls:
     1792        kfree(icode->gpr_map);
     1793__err_gpr:
     1794        kfree(icode);
    17481795        return err;
    17491796}
     
    17561803/* when volume = max, then copy only to avoid volume modification */
    17571804/* with iMAC0 (negative values) */
    1758 static void __devinit _volume(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol)
     1805static void _volume(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol)
    17591806{
    17601807        OP(icode, ptr, iMAC0, dst, C_00000000, src, vol);
     
    17631810        OP(icode, ptr, iACC3, dst, src, C_00000000, C_00000000);
    17641811}
    1765 static void __devinit _volume_add(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol)
     1812static void _volume_add(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol)
    17661813{
    17671814        OP(icode, ptr, iANDXOR, C_00000000, vol, C_ffffffff, C_7fffffff);
     
    17711818        OP(icode, ptr, iMAC0, dst, dst, src, vol);
    17721819}
    1773 static void __devinit _volume_out(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol)
     1820static void _volume_out(struct snd_emu10k1_fx8010_code *icode, u32 *ptr, u32 dst, u32 src, u32 vol)
    17741821{
    17751822        OP(icode, ptr, iANDXOR, C_00000000, vol, C_ffffffff, C_7fffffff);
     
    18021849
    18031850
    1804 static int __devinit _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)
     1851static int _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)
    18051852{
    18061853        int err, i, z, gpr, tmp, playback, capture;
     
    18101857        struct snd_emu10k1_fx8010_control_gpr *controls = NULL, *ctl;
    18111858        u32 *gpr_map;
    1812         mm_segment_t seg;
    1813 
    1814         if ((icode = kzalloc(sizeof(*icode), GFP_KERNEL)) == NULL)
    1815                 return -ENOMEM;
    1816         if ((icode->gpr_map = (u_int32_t __user *)
    1817              kcalloc(256 + 160 + 160 + 2 * 512, sizeof(u_int32_t),
    1818                      GFP_KERNEL)) == NULL ||
    1819             (controls = kcalloc(SND_EMU10K1_GPR_CONTROLS,
    1820                                 sizeof(struct snd_emu10k1_fx8010_control_gpr),
    1821                                 GFP_KERNEL)) == NULL ||
    1822             (ipcm = kzalloc(sizeof(*ipcm), GFP_KERNEL)) == NULL) {
    1823                 err = -ENOMEM;
    1824                 goto __err;
    1825         }
    1826         gpr_map = (u32 __force *)icode->gpr_map;
     1859
     1860        err = -ENOMEM;
     1861        icode = kzalloc(sizeof(*icode), GFP_KERNEL);
     1862        if (!icode)
     1863                return err;
     1864
     1865        icode->gpr_map = kcalloc(256 + 160 + 160 + 2 * 512,
     1866                                 sizeof(u_int32_t), GFP_KERNEL);
     1867        if (!icode->gpr_map)
     1868                goto __err_gpr;
     1869
     1870        controls = kcalloc(SND_EMU10K1_GPR_CONTROLS,
     1871                           sizeof(struct snd_emu10k1_fx8010_control_gpr),
     1872                           GFP_KERNEL);
     1873        if (!controls)
     1874                goto __err_ctrls;
     1875
     1876        ipcm = kzalloc(sizeof(*ipcm), GFP_KERNEL);
     1877        if (!ipcm)
     1878                goto __err_ipcm;
     1879
     1880        gpr_map = icode->gpr_map;
    18271881
    18281882        icode->tram_data_map = icode->gpr_map + 256;
     
    21582212
    21592213        ctl = &controls[i + 0];
    2160         ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     2214        ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER;
    21612215        strcpy(ctl->id.name, "Tone Control - Bass");
    21622216        ctl->vcount = 2;
     
    21652219        ctl->max = 40;
    21662220        ctl->value[0] = ctl->value[1] = 20;
     2221        ctl->tlv = snd_emu10k1_bass_treble_db_scale;
    21672222        ctl->translation = EMU10K1_GPR_TRANSLATION_BASS;
    21682223        ctl = &controls[i + 1];
    2169         ctl->id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
     2224        ctl->id.iface = (__force int)SNDRV_CTL_ELEM_IFACE_MIXER;
    21702225        strcpy(ctl->id.name, "Tone Control - Treble");
    21712226        ctl->vcount = 2;
     
    21742229        ctl->max = 40;
    21752230        ctl->value[0] = ctl->value[1] = 20;
     2231        ctl->tlv = snd_emu10k1_bass_treble_db_scale;
    21762232        ctl->translation = EMU10K1_GPR_TRANSLATION_TREBLE;
    21772233
     
    23162372                 * and EXTOUT_ALFE, so we can't connect inputs to them for multitrack recording.
    23172373                 *
    2318                  * Since only 14 of the 16 EXTINs are used, this is not a big problem.
    2319                  * We route AC97L and R to FX capture 14 and 15, SPDIF CD in to FX capture
    2320                  * 0 and 3, then the rest of the EXTINs to the corresponding FX capture
    2321                  * channel.  Multitrack recorders will still see the center/lfe output signal
     2374                 * Since only 14 of the 16 EXTINs are used, this is not a big problem. 
     2375                 * We route AC97L and R to FX capture 14 and 15, SPDIF CD in to FX capture 
     2376                 * 0 and 3, then the rest of the EXTINs to the corresponding FX capture 
     2377                 * channel.  Multitrack recorders will still see the center/lfe output signal 
    23222378                 * on the second and third channels.
    23232379                 */
     
    23322388                        OP(icode, &ptr, iACC3, FXBUS2(z), C_00000000, C_00000000, EXTIN(z));
    23332389        }
    2334        
     2390           
    23352391
    23362392        if (gpr > tmp) {
     
    23512407        if ((err = snd_emu10k1_fx8010_tram_setup(emu, ipcm->buffer_size)) < 0)
    23522408                goto __err;
    2353         seg = snd_enter_user();
    23542409        icode->gpr_add_control_count = i;
    2355         icode->gpr_add_controls = (struct snd_emu10k1_fx8010_control_gpr __user *)controls;
     2410        icode->gpr_add_controls = controls;
    23562411        emu->support_tlv = 1; /* support TLV */
    2357         err = snd_emu10k1_icode_poke(emu, icode);
     2412        err = snd_emu10k1_icode_poke(emu, icode, true);
    23582413        emu->support_tlv = 0; /* clear again */
    2359         snd_leave_user(seg);
    23602414        if (err >= 0)
    23612415                err = snd_emu10k1_ipcm_poke(emu, ipcm);
    2362       __err:
     2416__err:
    23632417        kfree(ipcm);
     2418__err_ipcm:
    23642419        kfree(controls);
    2365         if (icode != NULL) {
    2366                 kfree((void __force *)icode->gpr_map);
    2367                 kfree(icode);
    2368         }
     2420__err_ctrls:
     2421        kfree(icode->gpr_map);
     2422__err_gpr:
     2423        kfree(icode);
    23692424        return err;
    23702425}
    23712426
    2372 int __devinit snd_emu10k1_init_efx(struct snd_emu10k1 *emu)
     2427int snd_emu10k1_init_efx(struct snd_emu10k1 *emu)
    23732428{
    23742429        spin_lock_init(&emu->fx8010.irq_lock);
     
    24352490
    24362491        if (size > 0) {
    2437                 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(emu->pci),
     2492                if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &emu->pci->dev,
    24382493                                        size * 2, &emu->fx8010.etram_pages) < 0)
    24392494                        return -ENOMEM;
     
    24542509}
    24552510
    2456 static void copy_string(char *dst, char *src, char *null, int idx)
     2511static void copy_string(char *dst, const char *src, const char *null, int idx)
    24572512{
    24582513        if (src == NULL)
     
    24652520                                   struct snd_emu10k1_fx8010_info *info)
    24662521{
    2467         char **fxbus, **extin, **extout;
     2522        const char * const *fxbus, * const *extin, * const *extout;
    24682523        unsigned short fxbus_mask, extin_mask, extout_mask;
    24692524        int res;
     
    25022557                return put_user(SNDRV_EMU10K1_VERSION, (int __user *)argp);
    25032558        case SNDRV_EMU10K1_IOCTL_INFO:
    2504                 info = kmalloc(sizeof(*info), GFP_KERNEL);
     2559                info = kzalloc(sizeof(*info), GFP_KERNEL);
    25052560                if (!info)
    25062561                        return -ENOMEM;
     
    25192574                if (IS_ERR(icode))
    25202575                        return PTR_ERR(icode);
    2521                 res = snd_emu10k1_icode_poke(emu, icode);
     2576                res = snd_emu10k1_icode_poke(emu, icode, false);
    25222577                kfree(icode);
    25232578                return res;
     
    26232678}
    26242679
    2625 int __devinit snd_emu10k1_fx8010_new(struct snd_emu10k1 *emu, int device, struct snd_hwdep ** rhwdep)
     2680int snd_emu10k1_fx8010_new(struct snd_emu10k1 *emu, int device)
    26262681{
    26272682        struct snd_hwdep *hw;
    26282683        int err;
    26292684       
    2630         if (rhwdep)
    2631                 *rhwdep = NULL;
    26322685        if ((err = snd_hwdep_new(emu->card, "FX8010", device, &hw)) < 0)
    26332686                return err;
     
    26382691        hw->ops.release = snd_emu10k1_fx8010_release;
    26392692        hw->private_data = emu;
    2640         if (rhwdep)
    2641                 *rhwdep = hw;
    26422693        return 0;
    26432694}
    26442695
    2645 #ifdef CONFIG_PM
    2646 int __devinit snd_emu10k1_efx_alloc_pm_buffer(struct snd_emu10k1 *emu)
     2696#ifdef CONFIG_PM_SLEEP
     2697int snd_emu10k1_efx_alloc_pm_buffer(struct snd_emu10k1 *emu)
    26472698{
    26482699        int len;
    26492700
    26502701        len = emu->audigy ? 0x200 : 0x100;
    2651         emu->saved_gpr = kmalloc(len * 4, GFP_KERNEL);
     2702        emu->saved_gpr = kmalloc_array(len, 4, GFP_KERNEL);
    26522703        if (! emu->saved_gpr)
    26532704                return -ENOMEM;
    26542705        len = emu->audigy ? 0x100 : 0xa0;
    2655         emu->tram_val_saved = kmalloc(len * 4, GFP_KERNEL);
    2656         emu->tram_addr_saved = kmalloc(len * 4, GFP_KERNEL);
     2706        emu->tram_val_saved = kmalloc_array(len, 4, GFP_KERNEL);
     2707        emu->tram_addr_saved = kmalloc_array(len, 4, GFP_KERNEL);
    26572708        if (! emu->tram_val_saved || ! emu->tram_addr_saved)
    26582709                return -ENOMEM;
    26592710        len = emu->audigy ? 2 * 1024 : 2 * 512;
     2711#ifdef TARGET_OS2
     2712        emu->saved_icode = vmalloc(array_size(len, 4));
     2713#else
    26602714        emu->saved_icode = vmalloc(len * 4);
     2715#endif
    26612716        if (! emu->saved_icode)
    26622717                return -ENOMEM;
Note: See TracChangeset for help on using the changeset viewer.