Changeset 750


Ignore:
Timestamp:
Oct 3, 2022, 4:24:46 AM (3 years ago)
Author:
Paul Smedley
Message:

Update linux core to the 6.0 kernel

Location:
GPL/branches/uniaud32-exp
Files:
1 added
45 edited

Legend:

Unmodified
Added
Removed
  • GPL/branches/uniaud32-exp/alsa-kernel/core/control.c

    r739 r750  
    161161                return;
    162162        read_lock_irqsave(&card->ctl_files_rwlock, flags);
    163 #if IS_ENABLED(CONFIG_SND_MIXER_OSS)
     163//#if (IS_ENABLED(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS))
     164#if defined(CONFIG_SND_MIXER_OSS)
    164165        card->mixer_oss_change_count++;
    165166#endif
     
    378379}
    379380
     381/* check whether the given id is contained in the given kctl */
     382static bool elem_id_matches(const struct snd_kcontrol *kctl,
     383                            const struct snd_ctl_elem_id *id)
     384{
     385        return kctl->id.iface == id->iface &&
     386                kctl->id.device == id->device &&
     387                kctl->id.subdevice == id->subdevice &&
     388                !strncmp(kctl->id.name, id->name, sizeof(kctl->id.name)) &&
     389                kctl->id.index <= id->index &&
     390                kctl->id.index + kctl->count > id->index;
     391}
     392
     393#ifdef CONFIG_SND_CTL_FAST_LOOKUP
     394/* Compute a hash key for the corresponding ctl id
     395 * It's for the name lookup, hence the numid is excluded.
     396 * The hash key is bound in LONG_MAX to be used for Xarray key.
     397 */
     398#define MULTIPLIER      37
     399static unsigned long get_ctl_id_hash(const struct snd_ctl_elem_id *id)
     400{
     401        int i;
     402        unsigned long h;
     403
     404        h = id->iface;
     405        h = MULTIPLIER * h + id->device;
     406        h = MULTIPLIER * h + id->subdevice;
     407        for (i = 0; i < SNDRV_CTL_ELEM_ID_NAME_MAXLEN && id->name[i]; i++)
     408                h = MULTIPLIER * h + id->name[i];
     409        h = MULTIPLIER * h + id->index;
     410        h &= LONG_MAX;
     411        return h;
     412}
     413
     414/* add hash entries to numid and ctl xarray tables */
     415static void add_hash_entries(struct snd_card *card,
     416                             struct snd_kcontrol *kcontrol)
     417{
     418        struct snd_ctl_elem_id id = kcontrol->id;
     419        int i;
     420
     421        xa_store_range(&card->ctl_numids, kcontrol->id.numid,
     422                       kcontrol->id.numid + kcontrol->count - 1,
     423                       kcontrol, GFP_KERNEL);
     424
     425        for (i = 0; i < kcontrol->count; i++) {
     426                id.index = kcontrol->id.index + i;
     427                if (xa_insert(&card->ctl_hash, get_ctl_id_hash(&id),
     428                              kcontrol, GFP_KERNEL)) {
     429                        /* skip hash for this entry, noting we had collision */
     430                        card->ctl_hash_collision = true;
     431                        dev_dbg(card->dev, "ctl_hash collision %d:%s:%d\n",
     432                                id.iface, id.name, id.index);
     433                }
     434        }
     435}
     436
     437/* remove hash entries that have been added */
     438static void remove_hash_entries(struct snd_card *card,
     439                                struct snd_kcontrol *kcontrol)
     440{
     441        struct snd_ctl_elem_id id = kcontrol->id;
     442        struct snd_kcontrol *matched;
     443        unsigned long h;
     444        int i;
     445
     446        for (i = 0; i < kcontrol->count; i++) {
     447                xa_erase(&card->ctl_numids, id.numid);
     448                h = get_ctl_id_hash(&id);
     449                matched = xa_load(&card->ctl_hash, h);
     450                if (matched && (matched == kcontrol ||
     451                                elem_id_matches(matched, &id)))
     452                        xa_erase(&card->ctl_hash, h);
     453                id.index++;
     454                id.numid++;
     455        }
     456}
     457#else /* CONFIG_SND_CTL_FAST_LOOKUP */
     458static inline void add_hash_entries(struct snd_card *card,
     459                                    struct snd_kcontrol *kcontrol)
     460{
     461}
     462static inline void remove_hash_entries(struct snd_card *card,
     463                                       struct snd_kcontrol *kcontrol)
     464{
     465}
     466#endif /* CONFIG_SND_CTL_FAST_LOOKUP */
     467
    380468enum snd_ctl_add_mode {
    381469        CTL_ADD_EXCLUSIVE, CTL_REPLACE, CTL_ADD_ON_REPLACE,
     
    422510        card->last_numid += kcontrol->count;
    423511
     512        add_hash_entries(card, kcontrol);
     513
    424514        for (idx = 0; idx < kcontrol->count; idx++)
    425515                snd_ctl_notify_one(card, SNDRV_CTL_EVENT_MASK_ADD, kcontrol, idx);
     
    493583EXPORT_SYMBOL(snd_ctl_replace);
    494584
     585static int __snd_ctl_remove(struct snd_card *card,
     586                            struct snd_kcontrol *kcontrol,
     587                            bool remove_hash)
     588{
     589        unsigned int idx;
     590
     591        if (snd_BUG_ON(!card || !kcontrol))
     592                return -EINVAL;
     593        list_del(&kcontrol->list);
     594
     595        if (remove_hash)
     596                remove_hash_entries(card, kcontrol);
     597
     598        card->controls_count -= kcontrol->count;
     599        for (idx = 0; idx < kcontrol->count; idx++)
     600                snd_ctl_notify_one(card, SNDRV_CTL_EVENT_MASK_REMOVE, kcontrol, idx);
     601        snd_ctl_free_one(kcontrol);
     602        return 0;
     603}
     604
    495605/**
    496606 * snd_ctl_remove - remove the control from the card and release it
     
    506616int snd_ctl_remove(struct snd_card *card, struct snd_kcontrol *kcontrol)
    507617{
    508         unsigned int idx;
    509 
    510         if (snd_BUG_ON(!card || !kcontrol))
    511                 return -EINVAL;
    512         list_del(&kcontrol->list);
    513         card->controls_count -= kcontrol->count;
    514         for (idx = 0; idx < kcontrol->count; idx++)
    515                 snd_ctl_notify_one(card, SNDRV_CTL_EVENT_MASK_REMOVE, kcontrol, idx);
    516         snd_ctl_free_one(kcontrol);
    517         return 0;
     618        return __snd_ctl_remove(card, kcontrol, true);
    518619}
    519620EXPORT_SYMBOL(snd_ctl_remove);
     
    656757                return -ENOENT;
    657758        }
     759        remove_hash_entries(card, kctl);
    658760        kctl->id = *dst_id;
    659761        kctl->id.numid = card->last_numid + 1;
    660762        card->last_numid += kctl->count;
     763        add_hash_entries(card, kctl);
    661764        up_write(&card->controls_rwsem);
    662765        return 0;
    663766}
    664767EXPORT_SYMBOL(snd_ctl_rename_id);
     768
     769#ifndef CONFIG_SND_CTL_FAST_LOOKUP
     770static struct snd_kcontrol *
     771snd_ctl_find_numid_slow(struct snd_card *card, unsigned int numid)
     772{
     773        struct snd_kcontrol *kctl;
     774
     775        list_for_each_entry(kctl, &card->controls, list, struct snd_kcontrol) {
     776                if (kctl->id.numid <= numid && kctl->id.numid + kctl->count > numid)
     777                        return kctl;
     778        }
     779        return NULL;
     780}
     781#endif /* !CONFIG_SND_CTL_FAST_LOOKUP */
    665782
    666783/**
     
    679796struct snd_kcontrol *snd_ctl_find_numid(struct snd_card *card, unsigned int numid)
    680797{
    681         struct snd_kcontrol *kctl;
    682 
    683798        if (snd_BUG_ON(!card || !numid))
    684799                return NULL;
    685         list_for_each_entry(kctl, &card->controls, list, struct snd_kcontrol) {
    686                 if (kctl->id.numid <= numid && kctl->id.numid + kctl->count > numid)
    687                         return kctl;
    688         }
    689         return NULL;
     800#ifdef CONFIG_SND_CTL_FAST_LOOKUP
     801        return xa_load(&card->ctl_numids, numid);
     802#else
     803        return snd_ctl_find_numid_slow(card, numid);
     804#endif
    690805}
    691806EXPORT_SYMBOL(snd_ctl_find_numid);
     
    713828        if (id->numid != 0)
    714829                return snd_ctl_find_numid(card, id->numid);
    715         list_for_each_entry(kctl, &card->controls, list, struct snd_kcontrol) {
    716                 if (kctl->id.iface != id->iface)
    717                         continue;
    718                 if (kctl->id.device != id->device)
    719                         continue;
    720                 if (kctl->id.subdevice != id->subdevice)
    721                         continue;
    722                 if (strncmp(kctl->id.name, id->name, sizeof(kctl->id.name)))
    723                         continue;
    724                 if (kctl->id.index > id->index)
    725                         continue;
    726                 if (kctl->id.index + kctl->count <= id->index)
    727                         continue;
     830#ifdef CONFIG_SND_CTL_FAST_LOOKUP
     831        kctl = xa_load(&card->ctl_hash, get_ctl_id_hash(id));
     832        if (kctl && elem_id_matches(kctl, id))
    728833                return kctl;
    729         }
     834        if (!card->ctl_hash_collision)
     835                return NULL; /* we can rely on only hash table */
     836#endif
     837        /* no matching in hash table - try all as the last resort */
     838        list_for_each_entry(kctl, &card->controls, list, struct snd_kcontrol)
     839                if (elem_id_matches(kctl, id))
     840                        return kctl;
    730841        return NULL;
    731842}
     
    869980};
    870981
    871 #ifdef CONFIG_SND_CTL_VALIDATION
    872982/* fill the remaining snd_ctl_elem_value data with the given pattern */
    873983static void fill_remaining_elem_value(struct snd_ctl_elem_value *control,
     
    886996                                  const struct snd_ctl_elem_value *control,
    887997                                  const struct snd_ctl_elem_info *info,
    888                                   int i)
     998                                  int i, bool print_error)
    889999{
    8901000        long long lval, lmin, lmax, lstep;
     
    9201030
    9211031        if (lval < lmin || lval > lmax) {
    922                 dev_err(card->dev,
    923                         "control %i:%i:%i:%s:%i: value out of range %lld (%lld/%lld) at count %i\n",
    924                         control->id.iface, control->id.device,
    925                         control->id.subdevice, control->id.name,
    926                         control->id.index, lval, lmin, lmax, i);
     1032                if (print_error)
     1033                        dev_err(card->dev,
     1034                                "control %i:%i:%i:%s:%i: value out of range %lld (%lld/%lld) at count %i\n",
     1035                                control->id.iface, control->id.device,
     1036                                control->id.subdevice, control->id.name,
     1037                                control->id.index, lval, lmin, lmax, i);
    9271038                return -EINVAL;
    9281039        }
     
    9301041                div64_u64_rem(lval, lstep, &rem);
    9311042                if (rem) {
    932                         dev_err(card->dev,
    933                                 "control %i:%i:%i:%s:%i: unaligned value %lld (step %lld) at count %i\n",
    934                                 control->id.iface, control->id.device,
    935                                 control->id.subdevice, control->id.name,
    936                                 control->id.index, lval, lstep, i);
     1043                        if (print_error)
     1044                                dev_err(card->dev,
     1045                                        "control %i:%i:%i:%s:%i: unaligned value %lld (step %lld) at count %i\n",
     1046                                        control->id.iface, control->id.device,
     1047                                        control->id.subdevice, control->id.name,
     1048                                        control->id.index, lval, lstep, i);
    9371049                        return -EINVAL;
    9381050                }
     
    9421054}
    9431055
    944 /* perform sanity checks to the given snd_ctl_elem_value object */
    945 static int sanity_check_elem_value(struct snd_card *card,
    946                                    const struct snd_ctl_elem_value *control,
    947                                    const struct snd_ctl_elem_info *info,
    948                                    u32 pattern)
    949 {
    950         size_t offset;
    951         int i, ret = 0;
    952         u32 *p;
     1056/* check whether the all input values are valid for the given elem value */
     1057static int sanity_check_input_values(struct snd_card *card,
     1058                                     const struct snd_ctl_elem_value *control,
     1059                                     const struct snd_ctl_elem_info *info,
     1060                                     bool print_error)
     1061{
     1062        int i, ret;
    9531063
    9541064        switch (info->type) {
     
    9581068        case SNDRV_CTL_ELEM_TYPE_ENUMERATED:
    9591069                for (i = 0; i < info->count; i++) {
    960                         ret = sanity_check_int_value(card, control, info, i);
     1070                        ret = sanity_check_int_value(card, control, info, i,
     1071                                                     print_error);
    9611072                        if (ret < 0)
    9621073                                return ret;
     
    9661077                break;
    9671078        }
     1079
     1080        return 0;
     1081}
     1082
     1083/* perform sanity checks to the given snd_ctl_elem_value object */
     1084static int sanity_check_elem_value(struct snd_card *card,
     1085                                   const struct snd_ctl_elem_value *control,
     1086                                   const struct snd_ctl_elem_info *info,
     1087                                   u32 pattern)
     1088{
     1089        size_t offset;
     1090        int ret;
     1091        u32 *p;
     1092
     1093        ret = sanity_check_input_values(card, control, info, true);
     1094        if (ret < 0)
     1095                return ret;
    9681096
    9691097        /* check whether the remaining area kept untouched */
     
    9811109        return ret;
    9821110}
    983 #else
    984 static inline void fill_remaining_elem_value(struct snd_ctl_elem_value *control,
    985                                              struct snd_ctl_elem_info *info,
    986                                              u32 pattern)
    987 {
    988 }
    989 
    990 static inline int sanity_check_elem_value(struct snd_card *card,
    991                                           struct snd_ctl_elem_value *control,
    992                                           struct snd_ctl_elem_info *info,
    993                                           u32 pattern)
    994 {
    995         return 0;
    996 }
    997 #endif
    9981111
    9991112static int __snd_ctl_elem_info(struct snd_card *card,
     
    10911204        snd_ctl_build_ioff(&control->id, kctl, index_offset);
    10921205
    1093 #ifdef CONFIG_SND_CTL_VALIDATION
     1206#ifdef CONFIG_SND_CTL_DEBUG
    10941207        /* info is needed only for validation */
    10951208        memset(&info, 0, sizeof(info));
     
    11681281        snd_ctl_build_ioff(&control->id, kctl, index_offset);
    11691282        result = snd_power_ref_and_wait(card);
     1283        /* validate input values */
     1284#ifndef TARGET_OS2
     1285        if ((IS_ENABLED(CONFIG_SND_CTL_INPUT_VALIDATION) || defined(CONFIG_SND_CTL_INPUT_VALIDATION)) && !result) {
     1286#else
     1287        if (!result) {
     1288#endif
     1289                struct snd_ctl_elem_info info;
     1290
     1291                memset(&info, 0, sizeof(info));
     1292                info.id = control->id;
     1293                result = __snd_ctl_elem_info(card, kctl, &info, NULL);
     1294                if (!result)
     1295                        result = sanity_check_input_values(card, control, &info,
     1296                                                           false);
     1297        }
    11701298        if (!result)
    11711299                result = kctl->put(kctl, control);
     
    19442072 *
    19452073 * called from each device manager like pcm.c, hwdep.c, etc.
     2074 *
     2075 * Return: zero if successful, or a negative error code
    19462076 */
    19472077int snd_ctl_register_ioctl(snd_kctl_ioctl_func_t fcn)
     
    19562086 * control-ioctls
    19572087 * @fcn: ioctl callback function
     2088 *
     2089 * Return: zero if successful, or a negative error code
    19582090 */
    19592091int snd_ctl_register_ioctl_compat(snd_kctl_ioctl_func_t fcn)
     
    19912123 * snd_ctl_unregister_ioctl - de-register the device-specific control-ioctls
    19922124 * @fcn: ioctl callback function to unregister
     2125 *
     2126 * Return: zero if successful, or a negative error code
    19932127 */
    19942128int snd_ctl_unregister_ioctl(snd_kctl_ioctl_func_t fcn)
     
    20032137 * 32bit control-ioctls
    20042138 * @fcn: ioctl callback function to unregister
     2139 *
     2140 * Return: zero if successful, or a negative error code
    20052141 */
    20062142int snd_ctl_unregister_ioctl_compat(snd_kctl_ioctl_func_t fcn)
     
    20582194 * @module_name: Name of the kernel module (NULL == build-in)
    20592195 *
    2060  * Return an error code when the module cannot be loaded.
     2196 * Return: zero if successful, or an error code when the module cannot be loaded
    20612197 */
    20622198int snd_ctl_request_layer(const char *module_name)
     
    22092345        while (!list_empty(&card->controls)) {
    22102346                control = snd_kcontrol(card->controls.next);
    2211                 snd_ctl_remove(card, control);
    2212         }
     2347                __snd_ctl_remove(card, control, false);
     2348        }
     2349
     2350#ifdef CONFIG_SND_CTL_FAST_LOOKUP
     2351        xa_destroy(&card->ctl_numids);
     2352        xa_destroy(&card->ctl_hash);
     2353#endif
    22132354        up_write(&card->controls_rwsem);
    22142355        put_device(&card->ctl_dev);
     
    22552396 * This is a function that can be used as info callback for a standard
    22562397 * boolean control with a single mono channel.
     2398 *
     2399 * Return: Zero (always successful)
    22572400 */
    22582401int snd_ctl_boolean_mono_info(struct snd_kcontrol *kcontrol,
     
    22752418 * This is a function that can be used as info callback for a standard
    22762419 * boolean control with stereo two channels.
     2420 *
     2421 * Return: Zero (always successful)
    22772422 */
    22782423int snd_ctl_boolean_stereo_info(struct snd_kcontrol *kcontrol,
     
    22982443 * the caller has to fill @info->access.
    22992444 *
    2300  * Return: Zero.
     2445 * Return: Zero (always successful)
    23012446 */
    23022447int snd_ctl_enum_info(struct snd_ctl_elem_info *info, unsigned int channels,
  • GPL/branches/uniaud32-exp/alsa-kernel/core/device.c

    r629 r750  
    248248 * @SNDRV_DEV_DISCONNECTED is returned.
    249249 * Or for a non-existing device, -1 is returned as an error.
     250 *
     251 * Return: the current state, or -1 if not found
    250252 */
    251253int snd_device_get_state(struct snd_card *card, void *device_data)
  • GPL/branches/uniaud32-exp/alsa-kernel/core/info.c

    r739 r750  
    873873 * This proc file entry will be registered via snd_card_register() call, and
    874874 * it will be removed automatically at the card removal, too.
     875 *
     876 * Return: zero if successful, or a negative error code
    875877 */
    876878int snd_card_rw_proc_new(struct snd_card *card, const char *name,
  • GPL/branches/uniaud32-exp/alsa-kernel/core/init.c

    r749 r750  
    218218 * devres call orders.  You can use snd_card_free_on_error() helper for
    219219 * handling it more easily.
     220 *
     221 * Return: zero if successful, or a negative error code
    220222 */
    221223int snd_devm_card_new(struct device *parent, int idx, const char *xid,
     
    252254 * the probe callback.  It's just a small helper for simplifying the error
    253255 * handling with the managed devices.
     256 *
     257 * Return: zero if successful, or a negative error code
    254258 */
    255259int snd_card_free_on_error(struct device *dev, int ret)
     
    315319        INIT_LIST_HEAD(&card->controls);
    316320        INIT_LIST_HEAD(&card->ctl_files);
     321#ifdef CONFIG_SND_CTL_FAST_LOOKUP
     322        xa_init(&card->ctl_numids);
     323        xa_init(&card->ctl_hash);
     324#endif
    317325        spin_lock_init(&card->files_lock);
    318326        INIT_LIST_HEAD(&card->files_list);
     
    371379 * Returns a card object corresponding to the given index or NULL if not found.
    372380 * Release the object via snd_card_unref().
     381 *
     382 * Return: a card object or NULL
    373383 */
    374384struct snd_card *snd_card_ref(int idx)
     
    612622 * is still in use, the function returns before freeing the resources.
    613623 * The card resources will be freed when the refcount gets to zero.
     624 *
     625 * Return: zero if successful, or a negative error code
    614626 */
    615627int snd_card_free_when_closed(struct snd_card *card)
     
    781793{
    782794        struct snd_card *card = container_of(dev, struct snd_card, card_dev);
    783         return scnprintf(buf, PAGE_SIZE, "%s\n", card->id);
     795        return sysfs_emit(buf, "%s\n", card->id);
    784796}
    785797
     
    819831{
    820832        struct snd_card *card = container_of(dev, struct snd_card, card_dev);
    821         return scnprintf(buf, PAGE_SIZE, "%i\n", card->number);
     833        return sysfs_emit(buf, "%i\n", card->number);
    822834}
    823835
     
    839851 * @card: card instance
    840852 * @group: attribute group to append
     853 *
     854 * Return: zero if successful, or a negative error code
    841855 */
    842856int snd_card_add_dev_attr(struct snd_card *card,
  • GPL/branches/uniaud32-exp/alsa-kernel/core/memalloc.c

    r737 r750  
    366366 * SNDRV_DMA_TYPE_VMALLOC type.
    367367 *
    368  * The function returns the snd_dma_buffer object at success, or NULL if failed.
     368 * Return: the snd_dma_buffer object at success, or NULL if failed
    369369 */
    370370struct snd_dma_buffer *
  • GPL/branches/uniaud32-exp/alsa-kernel/core/pcm.c

    r739 r750  
    220220 * snd_pcm_format_name - Return a name string for the given PCM format
    221221 * @format: PCM format
     222 *
     223 * Return: the format name string
    222224 */
    223225const char *snd_pcm_format_name(snd_pcm_format_t format)
     
    10381040        else
    10391041                str = strs[pcm->dev_class];
    1040         return sprintf(buf, "%s\n", str);
     1042        return sysfs_emit(buf, "%s\n", str);
    10411043}
    10421044
     
    11491151 * called for each registered PCM devices.  This exists only for PCM OSS
    11501152 * emulation, so far.
     1153 *
     1154 * Return: zero if successful, or a negative error code
    11511155 */
    11521156int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree)
  • GPL/branches/uniaud32-exp/alsa-kernel/core/pcm_memory.c

    r737 r750  
    359359 *
    360360 * Upon successful buffer allocation and setup, the function returns 0.
     361 *
     362 * Return: zero if successful, or a negative error code
    361363 */
    362364int snd_pcm_set_managed_buffer(struct snd_pcm_substream *substream, int type,
     
    378380 * Do pre-allocation to all substreams of the given pcm for the specified DMA
    379381 * type and size, and set the managed_buffer_alloc flag to each substream.
     382 *
     383 * Return: zero if successful, or a negative error code
    380384 */
    381385int snd_pcm_set_managed_buffer_all(struct snd_pcm *pcm, int type,
  • GPL/branches/uniaud32-exp/alsa-kernel/core/pcm_native.c

    r739 r750  
    34673467 * and it allows only the limited set of ioctls (hw_params, sw_params,
    34683468 * prepare, start, drain, drop, forward).
     3469 *
     3470 * Return: zero if successful, or a negative error code
    34693471 */
    34703472int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
     
    38713873 * This is the default mmap handler for PCM data.  When mmap pcm_ops is NULL,
    38723874 * this function is invoked implicitly.
     3875 *
     3876 * Return: zero if successful, or a negative error code
    38733877 */
    38743878int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream,
     
    38973901 * wants to mmap it, pass this function as mmap pcm_ops.  Note that this
    38983902 * is supposed to work only on limited architectures.
     3903 *
     3904 * Return: zero if successful, or a negative error code
    38993905 */
    39003906int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream,
  • GPL/branches/uniaud32-exp/alsa-kernel/core/rawmidi.c

    r711 r750  
    116116static bool snd_rawmidi_ready(struct snd_rawmidi_substream *substream)
    117117{
    118         struct snd_rawmidi_runtime *runtime = substream->runtime;
    119118        unsigned long flags;
    120119        bool ready;
    121120
    122         spin_lock_irqsave(&runtime->lock, flags);
    123         ready = __snd_rawmidi_ready(runtime);
    124         spin_unlock_irqrestore(&runtime->lock, flags);
     121        spin_lock_irqsave(&substream->lock, flags);
     122        ready = __snd_rawmidi_ready(substream->runtime);
     123        spin_unlock_irqrestore(&substream->lock, flags);
    125124        return ready;
    126125}
     
    144143}
    145144
    146 /* buffer refcount management: call with runtime->lock held */
     145/* buffer refcount management: call with substream->lock held */
    147146static inline void snd_rawmidi_buffer_ref(struct snd_rawmidi_runtime *runtime)
    148147{
     
    153152{
    154153        runtime->buffer_ref--;
     154}
     155
     156static void snd_rawmidi_buffer_ref_sync(struct snd_rawmidi_substream *substream)
     157{
     158        int loop = HZ;
     159
     160        spin_lock_irq(&substream->lock);
     161        while (substream->runtime->buffer_ref) {
     162                spin_unlock_irq(&substream->lock);
     163                if (!--loop) {
     164                        rmidi_err(substream->rmidi, "Buffer ref sync timeout\n");
     165                        return;
     166                }
     167                schedule_timeout_uninterruptible(1);
     168                spin_lock_irq(&substream->lock);
     169        }
     170        spin_unlock_irq(&substream->lock);
    155171}
    156172
     
    163179                return -ENOMEM;
    164180        runtime->substream = substream;
    165         spin_lock_init(&runtime->lock);
    166181        init_waitqueue_head(&runtime->sleep);
    167182        INIT_WORK(&runtime->event_work, snd_rawmidi_input_event_work);
     
    217232}
    218233
    219 static void reset_runtime_ptrs(struct snd_rawmidi_runtime *runtime,
     234static void reset_runtime_ptrs(struct snd_rawmidi_substream *substream,
    220235                               bool is_input)
    221236{
    222237        unsigned long flags;
    223238
    224         spin_lock_irqsave(&runtime->lock, flags);
    225         __reset_runtime_ptrs(runtime, is_input);
    226         spin_unlock_irqrestore(&runtime->lock, flags);
     239        spin_lock_irqsave(&substream->lock, flags);
     240        if (substream->opened && substream->runtime)
     241                __reset_runtime_ptrs(substream->runtime, is_input);
     242        spin_unlock_irqrestore(&substream->lock, flags);
    227243}
    228244
     
    230246{
    231247        snd_rawmidi_output_trigger(substream, 0);
    232         reset_runtime_ptrs(substream->runtime, false);
     248        reset_runtime_ptrs(substream, false);
    233249        return 0;
    234250}
     
    237253int snd_rawmidi_drain_output(struct snd_rawmidi_substream *substream)
    238254{
    239         int err;
     255        int err = 0;
    240256        long timeout;
    241         struct snd_rawmidi_runtime *runtime = substream->runtime;
    242 
    243         err = 0;
    244         runtime->drain = 1;
     257        struct snd_rawmidi_runtime *runtime;
     258
     259        spin_lock_irq(&substream->lock);
     260        runtime = substream->runtime;
     261        if (!substream->opened || !runtime || !runtime->buffer) {
     262                err = -EINVAL;
     263        } else {
     264                snd_rawmidi_buffer_ref(runtime);
     265                runtime->drain = 1;
     266        }
     267        spin_unlock_irq(&substream->lock);
     268        if (err < 0)
     269                return err;
     270
    245271#ifndef TARGET_OS2
    246272        timeout = wait_event_interruptible_timeout(runtime->sleep,
     
    250276        timeout = interruptible_sleep_on_timeout(&runtime->sleep, 10 * HZ);
    251277#endif
     278
     279        spin_lock_irq(&substream->lock);
    252280        if (signal_pending(current))
    253281                err = -ERESTARTSYS;
     
    259287        }
    260288        runtime->drain = 0;
     289        spin_unlock_irq(&substream->lock);
     290
    261291        if (err != -ERESTARTSYS) {
    262292                /* we need wait a while to make sure that Tx FIFOs are empty */
     
    267297                snd_rawmidi_drop_output(substream);
    268298        }
     299
     300        spin_lock_irq(&substream->lock);
     301        snd_rawmidi_buffer_unref(runtime);
     302        spin_unlock_irq(&substream->lock);
     303
    269304        return err;
    270305}
     
    274309{
    275310        snd_rawmidi_input_trigger(substream, 0);
    276         reset_runtime_ptrs(substream->runtime, true);
     311        reset_runtime_ptrs(substream, true);
    277312        return 0;
    278313}
     
    329364                        return err;
    330365                }
     366                spin_lock_irq(&substream->lock);
    331367                substream->opened = 1;
    332368                substream->active_sensing = 0;
     
    335371                substream->pid = get_pid(task_pid(current));
    336372                rmidi->streams[substream->stream].substream_opened++;
     373                spin_unlock_irq(&substream->lock);
    337374        }
    338375        substream->use_count++;
     
    539576                                snd_rawmidi_output_trigger(substream, 0);
    540577                }
    541         }
     578                snd_rawmidi_buffer_ref_sync(substream);
     579        }
     580        spin_lock_irq(&substream->lock);
     581        substream->opened = 0;
     582        substream->append = 0;
     583        spin_unlock_irq(&substream->lock);
    542584        substream->ops->close(substream);
    543585        if (substream->runtime->private_free)
    544586                substream->runtime->private_free(substream);
    545587        snd_rawmidi_runtime_free(substream);
    546         substream->opened = 0;
    547         substream->append = 0;
    548588        put_pid(substream->pid);
    549589        substream->pid = NULL;
     
    696736}
    697737
    698 static int resize_runtime_buffer(struct snd_rawmidi_runtime *runtime,
     738static int resize_runtime_buffer(struct snd_rawmidi_substream *substream,
    699739                                 struct snd_rawmidi_params *params,
    700740                                 bool is_input)
    701741{
     742        struct snd_rawmidi_runtime *runtime = substream->runtime;
    702743        char *newbuf, *oldbuf;
    703744        unsigned int framing = params->mode & SNDRV_RAWMIDI_MODE_FRAMING_MASK;
     
    713754                if (!newbuf)
    714755                        return -ENOMEM;
    715                 spin_lock_irq(&runtime->lock);
     756                spin_lock_irq(&substream->lock);
    716757                if (runtime->buffer_ref) {
    717                         spin_unlock_irq(&runtime->lock);
     758                        spin_unlock_irq(&substream->lock);
    718759                        kvfree(newbuf);
    719760                        return -EBUSY;
     
    723764                runtime->buffer_size = params->buffer_size;
    724765                __reset_runtime_ptrs(runtime, is_input);
    725                 spin_unlock_irq(&runtime->lock);
     766                spin_unlock_irq(&substream->lock);
    726767                kvfree(oldbuf);
    727768        }
     
    733774                              struct snd_rawmidi_params *params)
    734775{
     776        int err;
     777
     778        snd_rawmidi_drain_output(substream);
     779        mutex_lock(&substream->rmidi->open_mutex);
    735780        if (substream->append && substream->use_count > 1)
    736                 return -EBUSY;
    737         snd_rawmidi_drain_output(substream);
    738         substream->active_sensing = !params->no_active_sensing;
    739         return resize_runtime_buffer(substream->runtime, params, false);
     781                err = -EBUSY;
     782        else
     783                err = resize_runtime_buffer(substream, params, false);
     784
     785        if (!err)
     786                substream->active_sensing = !params->no_active_sensing;
     787        mutex_unlock(&substream->rmidi->open_mutex);
     788        return err;
    740789}
    741790EXPORT_SYMBOL(snd_rawmidi_output_params);
     
    748797        int err;
    749798
     799        snd_rawmidi_drain_input(substream);
     800        mutex_lock(&substream->rmidi->open_mutex);
    750801        if (framing == SNDRV_RAWMIDI_MODE_FRAMING_NONE && clock_type != SNDRV_RAWMIDI_MODE_CLOCK_NONE)
    751                 return -EINVAL;
     802                err = -EINVAL;
    752803        else if (clock_type > SNDRV_RAWMIDI_MODE_CLOCK_MONOTONIC_RAW)
    753                 return -EINVAL;
    754         if (framing > SNDRV_RAWMIDI_MODE_FRAMING_TSTAMP)
    755                 return -EINVAL;
    756         snd_rawmidi_drain_input(substream);
    757         err = resize_runtime_buffer(substream->runtime, params, true);
    758         if (err < 0)
    759                 return err;
    760 
    761         substream->framing = framing;
    762         substream->clock_type = clock_type;
     804                err = -EINVAL;
     805        else if (framing > SNDRV_RAWMIDI_MODE_FRAMING_TSTAMP)
     806                err = -EINVAL;
     807        else
     808                err = resize_runtime_buffer(substream, params, true);
     809
     810        if (!err) {
     811                substream->framing = framing;
     812                substream->clock_type = clock_type;
     813        }
     814        mutex_unlock(&substream->rmidi->open_mutex);
    763815        return 0;
    764816}
     
    773825        memset(status, 0, sizeof(*status));
    774826        status->stream = SNDRV_RAWMIDI_STREAM_OUTPUT;
    775         spin_lock_irq(&runtime->lock);
     827        spin_lock_irq(&substream->lock);
    776828        status->avail = runtime->avail;
    777         spin_unlock_irq(&runtime->lock);
     829        spin_unlock_irq(&substream->lock);
    778830        return 0;
    779831}
     
    786838        memset(status, 0, sizeof(*status));
    787839        status->stream = SNDRV_RAWMIDI_STREAM_INPUT;
    788         spin_lock_irq(&runtime->lock);
     840        spin_lock_irq(&substream->lock);
    789841        status->avail = runtime->avail;
    790842        status->xruns = runtime->xruns;
    791843        runtime->xruns = 0;
    792         spin_unlock_irq(&runtime->lock);
     844        spin_unlock_irq(&substream->lock);
    793845        return 0;
    794846}
     
    10921144        struct timespec64 ts64 = get_framing_tstamp(substream);
    10931145        int result = 0, count1;
    1094         struct snd_rawmidi_runtime *runtime = substream->runtime;
    1095 
    1096         if (!substream->opened)
    1097                 return -EBADFD;
    1098         if (runtime->buffer == NULL) {
     1146        struct snd_rawmidi_runtime *runtime;
     1147
     1148        spin_lock_irqsave(&substream->lock, flags);
     1149        if (!substream->opened) {
     1150                result = -EBADFD;
     1151                goto unlock;
     1152        }
     1153        runtime = substream->runtime;
     1154        if (!runtime || !runtime->buffer) {
    10991155                rmidi_dbg(substream->rmidi,
    11001156                          "snd_rawmidi_receive: input is not active!!!\n");
    1101                 return -EINVAL;
    1102         }
    1103 
    1104         spin_lock_irqsave(&runtime->lock, flags);
     1157                result = -EINVAL;
     1158                goto unlock;
     1159        }
     1160
    11051161        if (substream->framing == SNDRV_RAWMIDI_MODE_FRAMING_TSTAMP) {
    11061162                result = receive_with_tstamp_framing(substream, buffer, count, &ts64);
     
    11491205                        wake_up(&runtime->sleep);
    11501206        }
    1151         spin_unlock_irqrestore(&runtime->lock, flags);
     1207 unlock:
     1208        spin_unlock_irqrestore(&substream->lock, flags);
    11521209        return result;
    11531210}
     
    11641221        int err = 0;
    11651222
    1166         spin_lock_irqsave(&runtime->lock, flags);
     1223        spin_lock_irqsave(&substream->lock, flags);
    11671224        snd_rawmidi_buffer_ref(runtime);
    11681225        while (count > 0 && runtime->avail) {
     
    11821239                        memcpy(kernelbuf + result, runtime->buffer + appl_ptr, count1);
    11831240                if (userbuf) {
    1184                         spin_unlock_irqrestore(&runtime->lock, flags);
     1241                        spin_unlock_irqrestore(&substream->lock, flags);
    11851242                        if (copy_to_user(userbuf + result,
    11861243                                         runtime->buffer + appl_ptr, count1))
    11871244                                err = -EFAULT;
    1188                         spin_lock_irqsave(&runtime->lock, flags);
     1245                        spin_lock_irqsave(&substream->lock, flags);
    11891246                        if (err)
    11901247                                goto out;
     
    11951252 out:
    11961253        snd_rawmidi_buffer_unref(runtime);
    1197         spin_unlock_irqrestore(&runtime->lock, flags);
     1254        spin_unlock_irqrestore(&substream->lock, flags);
    11981255        return result > 0 ? result : err;
    11991256}
     
    12241281        result = 0;
    12251282        while (count > 0) {
    1226                 spin_lock_irq(&runtime->lock);
     1283                spin_lock_irq(&substream->lock);
    12271284                while (!__snd_rawmidi_ready(runtime)) {
    12281285                        wait_queue_entry_t wait;
    12291286
    12301287                        if ((file->f_flags & O_NONBLOCK) != 0 || result > 0) {
    1231                                 spin_unlock_irq(&runtime->lock);
     1288                                spin_unlock_irq(&substream->lock);
    12321289                                return result > 0 ? result : -EAGAIN;
    12331290                        }
     
    12351292                        add_wait_queue(&runtime->sleep, &wait);
    12361293                        set_current_state(TASK_INTERRUPTIBLE);
    1237                         spin_unlock_irq(&runtime->lock);
     1294                        spin_unlock_irq(&substream->lock);
    12381295                        schedule();
    12391296                        remove_wait_queue(&runtime->sleep, &wait);
     
    12421299                        if (signal_pending(current))
    12431300                                return result > 0 ? result : -ERESTARTSYS;
    1244                         spin_lock_irq(&runtime->lock);
     1301                        spin_lock_irq(&substream->lock);
    12451302                        if (!runtime->avail) {
    1246                                 spin_unlock_irq(&runtime->lock);
     1303                                spin_unlock_irq(&substream->lock);
    12471304                                return result > 0 ? result : -EIO;
    12481305                        }
    12491306                }
    1250                 spin_unlock_irq(&runtime->lock);
     1307                spin_unlock_irq(&substream->lock);
    12511308                count1 = snd_rawmidi_kernel_read1(substream,
    12521309                                                  (unsigned char __user *)buf,
     
    12701327int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream)
    12711328{
    1272         struct snd_rawmidi_runtime *runtime = substream->runtime;
     1329        struct snd_rawmidi_runtime *runtime;
    12731330        int result;
    12741331        unsigned long flags;
    12751332
    1276         if (runtime->buffer == NULL) {
     1333        spin_lock_irqsave(&substream->lock, flags);
     1334        runtime = substream->runtime;
     1335        if (!substream->opened || !runtime || !runtime->buffer) {
    12771336                rmidi_dbg(substream->rmidi,
    12781337                          "snd_rawmidi_transmit_empty: output is not active!!!\n");
    1279                 return 1;
    1280         }
    1281         spin_lock_irqsave(&runtime->lock, flags);
    1282         result = runtime->avail >= runtime->buffer_size;
    1283         spin_unlock_irqrestore(&runtime->lock, flags);
     1338                result = 1;
     1339        } else {
     1340                result = runtime->avail >= runtime->buffer_size;
     1341        }
     1342        spin_unlock_irqrestore(&substream->lock, flags);
    12841343        return result;
    12851344}
    12861345EXPORT_SYMBOL(snd_rawmidi_transmit_empty);
    12871346
    1288 /**
     1347/*
    12891348 * __snd_rawmidi_transmit_peek - copy data from the internal buffer
    12901349 * @substream: the rawmidi substream
     
    12941353 * This is a variant of snd_rawmidi_transmit_peek() without spinlock.
    12951354 */
    1296 int __snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
    1297                               unsigned char *buffer, int count)
     1355static int __snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
     1356                                       unsigned char *buffer, int count)
    12981357{
    12991358        int result, count1;
     
    13321391        return result;
    13331392}
    1334 EXPORT_SYMBOL(__snd_rawmidi_transmit_peek);
    13351393
    13361394/**
     
    13511409                              unsigned char *buffer, int count)
    13521410{
    1353         struct snd_rawmidi_runtime *runtime = substream->runtime;
    13541411        int result;
    13551412        unsigned long flags;
    13561413
    1357         spin_lock_irqsave(&runtime->lock, flags);
    1358         result = __snd_rawmidi_transmit_peek(substream, buffer, count);
    1359         spin_unlock_irqrestore(&runtime->lock, flags);
     1414        spin_lock_irqsave(&substream->lock, flags);
     1415        if (!substream->opened || !substream->runtime)
     1416                result = -EBADFD;
     1417        else
     1418                result = __snd_rawmidi_transmit_peek(substream, buffer, count);
     1419        spin_unlock_irqrestore(&substream->lock, flags);
    13601420        return result;
    13611421}
    13621422EXPORT_SYMBOL(snd_rawmidi_transmit_peek);
    13631423
    1364 /**
     1424/*
    13651425 * __snd_rawmidi_transmit_ack - acknowledge the transmission
    13661426 * @substream: the rawmidi substream
     
    13691429 * This is a variant of __snd_rawmidi_transmit_ack() without spinlock.
    13701430 */
    1371 int __snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count)
     1431static int __snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream,
     1432                                      int count)
    13721433{
    13731434        struct snd_rawmidi_runtime *runtime = substream->runtime;
     
    13891450        return count;
    13901451}
    1391 EXPORT_SYMBOL(__snd_rawmidi_transmit_ack);
    13921452
    13931453/**
     
    14041464int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count)
    14051465{
    1406         struct snd_rawmidi_runtime *runtime = substream->runtime;
    14071466        int result;
    14081467        unsigned long flags;
    14091468
    1410         spin_lock_irqsave(&runtime->lock, flags);
    1411         result = __snd_rawmidi_transmit_ack(substream, count);
    1412         spin_unlock_irqrestore(&runtime->lock, flags);
     1469        spin_lock_irqsave(&substream->lock, flags);
     1470        if (!substream->opened || !substream->runtime)
     1471                result = -EBADFD;
     1472        else
     1473                result = __snd_rawmidi_transmit_ack(substream, count);
     1474        spin_unlock_irqrestore(&substream->lock, flags);
    14131475        return result;
    14141476}
     
    14281490                         unsigned char *buffer, int count)
    14291491{
    1430         struct snd_rawmidi_runtime *runtime = substream->runtime;
    14311492        int result;
    14321493        unsigned long flags;
    14331494
    1434         spin_lock_irqsave(&runtime->lock, flags);
     1495        spin_lock_irqsave(&substream->lock, flags);
    14351496        if (!substream->opened)
    14361497                result = -EBADFD;
     
    14421503                        result = __snd_rawmidi_transmit_ack(substream, count);
    14431504        }
    1444         spin_unlock_irqrestore(&runtime->lock, flags);
     1505        spin_unlock_irqrestore(&substream->lock, flags);
    14451506        return result;
    14461507}
     
    14551516int snd_rawmidi_proceed(struct snd_rawmidi_substream *substream)
    14561517{
    1457         struct snd_rawmidi_runtime *runtime = substream->runtime;
     1518        struct snd_rawmidi_runtime *runtime;
    14581519        unsigned long flags;
    14591520        int count = 0;
    14601521
    1461         spin_lock_irqsave(&runtime->lock, flags);
    1462         if (runtime->avail < runtime->buffer_size) {
     1522        spin_lock_irqsave(&substream->lock, flags);
     1523        runtime = substream->runtime;
     1524        if (substream->opened && runtime &&
     1525            runtime->avail < runtime->buffer_size) {
    14631526                count = runtime->buffer_size - runtime->avail;
    14641527                __snd_rawmidi_transmit_ack(substream, count);
    14651528        }
    1466         spin_unlock_irqrestore(&runtime->lock, flags);
     1529        spin_unlock_irqrestore(&substream->lock, flags);
    14671530        return count;
    14681531}
     
    14851548
    14861549        result = 0;
    1487         spin_lock_irqsave(&runtime->lock, flags);
     1550        spin_lock_irqsave(&substream->lock, flags);
    14881551        if (substream->append) {
    14891552                if ((long)runtime->avail < count) {
    1490                         spin_unlock_irqrestore(&runtime->lock, flags);
     1553                        spin_unlock_irqrestore(&substream->lock, flags);
    14911554                        return -EAGAIN;
    14921555                }
     
    15101573                               kernelbuf + result, count1);
    15111574                else if (userbuf) {
    1512                         spin_unlock_irqrestore(&runtime->lock, flags);
     1575                        spin_unlock_irqrestore(&substream->lock, flags);
    15131576                        if (copy_from_user(runtime->buffer + appl_ptr,
    15141577                                           userbuf + result, count1)) {
    1515                                 spin_lock_irqsave(&runtime->lock, flags);
     1578                                spin_lock_irqsave(&substream->lock, flags);
    15161579                                result = result > 0 ? result : -EFAULT;
    15171580                                goto __end;
    15181581                        }
    1519                         spin_lock_irqsave(&runtime->lock, flags);
     1582                        spin_lock_irqsave(&substream->lock, flags);
    15201583                }
    15211584                result += count1;
     
    15251588        count1 = runtime->avail < runtime->buffer_size;
    15261589        snd_rawmidi_buffer_unref(runtime);
    1527         spin_unlock_irqrestore(&runtime->lock, flags);
     1590        spin_unlock_irqrestore(&substream->lock, flags);
    15281591        if (count1)
    15291592                snd_rawmidi_output_trigger(substream, 1);
     
    15551618        result = 0;
    15561619        while (count > 0) {
    1557                 spin_lock_irq(&runtime->lock);
     1620                spin_lock_irq(&substream->lock);
    15581621                while (!snd_rawmidi_ready_append(substream, count)) {
    15591622                        wait_queue_entry_t wait;
    15601623
    15611624                        if (file->f_flags & O_NONBLOCK) {
    1562                                 spin_unlock_irq(&runtime->lock);
     1625                                spin_unlock_irq(&substream->lock);
    15631626                                return result > 0 ? result : -EAGAIN;
    15641627                        }
     
    15661629                        add_wait_queue(&runtime->sleep, &wait);
    15671630                        set_current_state(TASK_INTERRUPTIBLE);
    1568                         spin_unlock_irq(&runtime->lock);
     1631                        spin_unlock_irq(&substream->lock);
    15691632                        timeout = schedule_timeout(30 * HZ);
    15701633                        remove_wait_queue(&runtime->sleep, &wait);
     
    15731636                        if (signal_pending(current))
    15741637                                return result > 0 ? result : -ERESTARTSYS;
    1575                         spin_lock_irq(&runtime->lock);
     1638                        spin_lock_irq(&substream->lock);
    15761639                        if (!runtime->avail && !timeout) {
    1577                                 spin_unlock_irq(&runtime->lock);
     1640                                spin_unlock_irq(&substream->lock);
    15781641                                return result > 0 ? result : -EIO;
    15791642                        }
    15801643                }
    1581                 spin_unlock_irq(&runtime->lock);
     1644                spin_unlock_irq(&substream->lock);
    15821645                count1 = snd_rawmidi_kernel_write1(substream, buf, NULL, count);
    15831646                if (count1 < 0)
     
    15901653        }
    15911654        if (file->f_flags & O_DSYNC) {
    1592                 spin_lock_irq(&runtime->lock);
     1655                spin_lock_irq(&substream->lock);
    15931656                while (runtime->avail != runtime->buffer_size) {
    15941657                        wait_queue_entry_t wait;
     
    15981661                        add_wait_queue(&runtime->sleep, &wait);
    15991662                        set_current_state(TASK_INTERRUPTIBLE);
    1600                         spin_unlock_irq(&runtime->lock);
     1663                        spin_unlock_irq(&substream->lock);
    16011664                        timeout = schedule_timeout(30 * HZ);
    16021665                        remove_wait_queue(&runtime->sleep, &wait);
     
    16051668                        if (runtime->avail == last_avail && !timeout)
    16061669                                return result > 0 ? result : -EIO;
    1607                         spin_lock_irq(&runtime->lock);
    1608                 }
    1609                 spin_unlock_irq(&runtime->lock);
     1670                        spin_lock_irq(&substream->lock);
     1671                }
     1672                spin_unlock_irq(&substream->lock);
    16101673        }
    16111674        return result;
     
    16781741                                    pid_vnr(substream->pid));
    16791742                                runtime = substream->runtime;
    1680                                 spin_lock_irq(&runtime->lock);
     1743                                spin_lock_irq(&substream->lock);
    16811744                                buffer_size = runtime->buffer_size;
    16821745                                avail = runtime->avail;
    1683                                 spin_unlock_irq(&runtime->lock);
     1746                                spin_unlock_irq(&substream->lock);
    16841747                                snd_iprintf(buffer,
    16851748                                    "  Mode         : %s\n"
     
    17051768                                            pid_vnr(substream->pid));
    17061769                                runtime = substream->runtime;
    1707                                 spin_lock_irq(&runtime->lock);
     1770                                spin_lock_irq(&substream->lock);
    17081771                                buffer_size = runtime->buffer_size;
    17091772                                avail = runtime->avail;
    17101773                                xruns = runtime->xruns;
    1711                                 spin_unlock_irq(&runtime->lock);
     1774                                spin_unlock_irq(&substream->lock);
    17121775                                snd_iprintf(buffer,
    17131776                                            "  Buffer size  : %lu\n"
     
    17631826                substream->rmidi = rmidi;
    17641827                substream->pstr = stream;
     1828                spin_lock_init(&substream->lock);
    17651829                list_add_tail(&substream->list, &stream->substreams);
    17661830                stream->substream_count++;
  • GPL/branches/uniaud32-exp/alsa-kernel/core/vmaster.c

    r629 r750  
    500500 *
    501501 * Apply the function @func to each follower kctl of the given vmaster kctl.
    502  * Returns 0 if successful, or a negative error code.
     502 *
     503 * Return: 0 if successful, or a negative error code
    503504 */
    504505int snd_ctl_apply_vmaster_followers(struct snd_kcontrol *kctl,
  • GPL/branches/uniaud32-exp/alsa-kernel/hda/ext/hdac_ext_controller.c

    r738 r750  
    1414#include <sound/hda_register.h>
    1515#include <sound/hdaudio_ext.h>
    16 
    17 /*
    18  * maximum HDAC capablities we should parse to avoid endless looping:
    19  * currently we have 4 extended caps, so this is future proof for now.
    20  * extend when this limit is seen meeting in real HW
    21  */
    22 #define HDAC_MAX_CAPS 10
    2316
    2417/*
  • GPL/branches/uniaud32-exp/alsa-kernel/hda/hdac_bus.c

    r693 r750  
    194194                        continue;
    195195                codec = bus->caddr_tbl[caddr & 0x0f];
    196                 if (!codec || !codec->dev.driver)
     196                if (!codec || !codec->registered)
    197197                        continue;
    198198                spin_unlock_irq(&bus->reg_lock);
  • GPL/branches/uniaud32-exp/alsa-kernel/hda/hdac_controller.c

    r710 r750  
    481481                snd_hdac_stream_updateb(azx_dev, SD_CTL, SD_INT_MASK, 0);
    482482
    483         /* disable SIE for all streams */
    484         snd_hdac_chip_writeb(bus, INTCTL, 0);
    485 
    486         /* disable controller CIE and GIE */
    487         snd_hdac_chip_updatel(bus, INTCTL, AZX_INT_CTRL_EN | AZX_INT_GLOBAL_EN, 0);
     483        /* disable SIE for all streams & disable controller CIE and GIE */
     484        snd_hdac_chip_writel(bus, INTCTL, 0);
    488485}
    489486
  • GPL/branches/uniaud32-exp/alsa-kernel/hda/trace.h

    r615 r750  
    2020        TP_PROTO(struct hdac_bus *bus, unsigned int cmd),
    2121        TP_ARGS(bus, cmd),
    22         TP_STRUCT__entry(__dynamic_array(char, msg, HDAC_MSG_MAX)),
     22        TP_STRUCT__entry(
     23                __string(name, dev_name((bus)->dev))
     24                __field(u32, cmd)
     25        ),
    2326        TP_fast_assign(
    24                 snprintf(__get_str(msg), HDAC_MSG_MAX,
    25                          "[%s:%d] val=0x%08x",
    26                          dev_name((bus)->dev), (cmd) >> 28, cmd);
     27                __assign_str(name, dev_name((bus)->dev));
     28                __entry->cmd = cmd;
    2729        ),
    28         TP_printk("%s", __get_str(msg))
     30        TP_printk("[%s:%d] val=0x%08x", __get_str(name), __entry->cmd >> 28, __entry->cmd)
    2931);
    3032
     
    3234        TP_PROTO(struct hdac_bus *bus, unsigned int addr, unsigned int res),
    3335        TP_ARGS(bus, addr, res),
    34         TP_STRUCT__entry(__dynamic_array(char, msg, HDAC_MSG_MAX)),
     36        TP_STRUCT__entry(
     37                __string(name, dev_name((bus)->dev))
     38                __field(u32, addr)
     39                __field(u32, res)
     40        ),
    3541        TP_fast_assign(
    36                 snprintf(__get_str(msg), HDAC_MSG_MAX,
    37                          "[%s:%d] val=0x%08x",
    38                          dev_name((bus)->dev), addr, res);
     42                __assign_str(name, dev_name((bus)->dev));
     43                __entry->addr = addr;
     44                __entry->res = res;
    3945        ),
    40         TP_printk("%s", __get_str(msg))
     46        TP_printk("[%s:%d] val=0x%08x", __get_str(name), __entry->addr, __entry->res)
    4147);
    4248
     
    4450        TP_PROTO(struct hdac_bus *bus, u32 res, u32 res_ex),
    4551        TP_ARGS(bus, res, res_ex),
    46         TP_STRUCT__entry(__dynamic_array(char, msg, HDAC_MSG_MAX)),
     52        TP_STRUCT__entry(
     53                __string(name, dev_name((bus)->dev))
     54                __field(u32, res)
     55                __field(u32, res_ex)
     56        ),
    4757        TP_fast_assign(
    48                 snprintf(__get_str(msg), HDAC_MSG_MAX,
    49                          "[%s:%d] res=0x%08x, res_ex=0x%08x",
    50                          dev_name((bus)->dev), res_ex & 0x0f, res, res_ex);
     58                __assign_str(name, dev_name((bus)->dev));
     59                __entry->res = res;
     60                __entry->res_ex = res_ex;
    5161        ),
    52         TP_printk("%s", __get_str(msg))
     62        TP_printk("[%s:%d] res=0x%08x, res_ex=0x%08x", __get_str(name),
     63                  __entry->res_ex & 0x0f, __entry->res, __entry->res_ex)
    5364);
    5465
  • GPL/branches/uniaud32-exp/alsa-kernel/include/sound/config.h

    r737 r750  
    2323#define CONFIG_PM
    2424#define CONFIG_PM_SLEEP
     25#define CONFIG_SND_CTL_INPUT_VALIDATION 0
    2526#ifdef DEBUG
    2627#define CONFIG_SND_DEBUG_DETECT
  • GPL/branches/uniaud32-exp/alsa-kernel/include/sound/control.h

    r739 r750  
    2424
    2525/* internal flag for skipping validations */
    26 #ifdef CONFIG_SND_CTL_VALIDATION
     26#ifdef CONFIG_SND_CTL_DEBUG
    2727#define SNDRV_CTL_ELEM_ACCESS_SKIP_CHECK        (1 << 24)
    2828#define snd_ctl_skip_validation(info) \
  • GPL/branches/uniaud32-exp/alsa-kernel/include/sound/core.h

    r739 r750  
    1818#include <linux/stringify.h>
    1919#include <linux/printk.h>
     20#include <linux/xarray.h>
    2021
    2122/* number of supported soundcards */
     
    107108        struct list_head controls;      /* all controls for this card */
    108109        struct list_head ctl_files;     /* active control files */
     110#ifdef CONFIG_SND_CTL_FAST_LOOKUP
     111        struct xarray ctl_numids;       /* hash table for numids */
     112        struct xarray ctl_hash;         /* hash table for ctl id matching */
     113        bool ctl_hash_collision;        /* ctl_hash collision seen? */
     114#endif
    109115
    110116        struct snd_info_entry *proc_root;       /* root for soundcard specific files */
  • GPL/branches/uniaud32-exp/alsa-kernel/include/sound/dmaengine_pcm.h

    r737 r750  
    1616 *   substream
    1717 * @substream: PCM substream
     18 *
     19 * Return: DMA transfer direction
    1820 */
    1921static inline enum dma_transfer_direction
  • GPL/branches/uniaud32-exp/alsa-kernel/include/sound/hda_codec.h

    r739 r750  
    232232        unsigned int configured:1; /* codec was configured */
    233233        unsigned int in_freeing:1; /* being released */
    234         unsigned int registered:1; /* codec was registered */
    235234        unsigned int display_power_control:1; /* needs display power */
    236235        unsigned int spdif_status_reset :1; /* needs to toggle SPDIF for each
  • GPL/branches/uniaud32-exp/alsa-kernel/include/sound/hdaudio.h

    r738 r750  
    9494        bool caps_overwriting:1; /* caps overwrite being in process */
    9595        bool cache_coef:1;      /* cache COEF read/write too */
     96        unsigned int registered:1; /* codec was registered */
    9697};
    9798
  • GPL/branches/uniaud32-exp/alsa-kernel/include/sound/hdmi-codec.h

    r697 r750  
    3333        unsigned int bit_clk_inv:1;
    3434        unsigned int frame_clk_inv:1;
    35         unsigned int bit_clk_master:1;
    36         unsigned int frame_clk_master:1;
     35        unsigned int bit_clk_provider:1;
     36        unsigned int frame_clk_provider:1;
    3737        /* bit_fmt could be standard PCM format or
    3838         * IEC958 encoded format. ALSA IEC958 plugin will pass
  • GPL/branches/uniaud32-exp/alsa-kernel/include/sound/madera-pdata.h

    r615 r750  
    1010#define MADERA_CODEC_PDATA_H
    1111
    12 #include <linux/kernel.h>
     12#include <linux/types.h>
    1313
    1414#define MADERA_MAX_INPUT                6
  • GPL/branches/uniaud32-exp/alsa-kernel/include/sound/pcm.h

    r739 r750  
    608608 * @substream: substream to check
    609609 *
    610  * Returns true if the given substream is being linked with others.
     610 * Return: true if the given substream is being linked with others
    611611 */
    612612static inline int snd_pcm_stream_linked(struct snd_pcm_substream *substream)
     
    681681 * @substream: substream to check
    682682 *
    683  * Returns true if the given substream is in the state RUNNING, or in the
     683 * Return: true if the given substream is in the state RUNNING, or in the
    684684 * state DRAINING for playback.
    685685 */
     
    695695 * @runtime: PCM runtime instance
    696696 * @size: size in bytes
     697 *
     698 * Return: the size in samples
    697699 */
    698700static inline ssize_t bytes_to_samples(struct snd_pcm_runtime *runtime, ssize_t size)
     
    705707 * @runtime: PCM runtime instance
    706708 * @size: size in bytes
     709 *
     710 * Return: the size in frames
    707711 */
    708712static inline snd_pcm_sframes_t bytes_to_frames(struct snd_pcm_runtime *runtime, ssize_t size)
     
    715719 * @runtime: PCM runtime instance
    716720 * @size: size in samples
     721 *
     722 * Return: the byte size
    717723 */
    718724static inline ssize_t samples_to_bytes(struct snd_pcm_runtime *runtime, ssize_t size)
     
    725731 * @runtime: PCM runtime instance
    726732 * @size: size in frames
     733 *
     734 * Return: the byte size
    727735 */
    728736static inline ssize_t frames_to_bytes(struct snd_pcm_runtime *runtime, snd_pcm_sframes_t size)
     
    735743 * @runtime: PCM runtime instance
    736744 * @bytes: size in bytes
     745 *
     746 * Return: true if aligned, or false if not
    737747 */
    738748static inline int frame_aligned(struct snd_pcm_runtime *runtime, ssize_t bytes)
     
    744754 * snd_pcm_lib_buffer_bytes - Get the buffer size of the current PCM in bytes
    745755 * @substream: PCM substream
     756 *
     757 * Return: buffer byte size
    746758 */
    747759static inline size_t snd_pcm_lib_buffer_bytes(struct snd_pcm_substream *substream)
     
    754766 * snd_pcm_lib_period_bytes - Get the period size of the current PCM in bytes
    755767 * @substream: PCM substream
     768 *
     769 * Return: period byte size
    756770 */
    757771static inline size_t snd_pcm_lib_period_bytes(struct snd_pcm_substream *substream)
     
    766780 *
    767781 * Result is between 0 ... (boundary - 1)
     782 *
     783 * Return: available frame size
    768784 */
    769785static inline snd_pcm_uframes_t snd_pcm_playback_avail(struct snd_pcm_runtime *runtime)
     
    795811 *
    796812 * Result is between 0 ... (boundary - 1)
     813 *
     814 * Return: available frame size
    797815 */
    798816static inline snd_pcm_uframes_t snd_pcm_capture_avail(struct snd_pcm_runtime *runtime)
     
    807825 * snd_pcm_playback_hw_avail - Get the queued space for playback
    808826 * @runtime: PCM runtime instance
     827 *
     828 * Return: available frame size
    809829 */
    810830static inline snd_pcm_sframes_t snd_pcm_playback_hw_avail(struct snd_pcm_runtime *runtime)
     
    816836 * snd_pcm_capture_hw_avail - Get the free space for capture
    817837 * @runtime: PCM runtime instance
     838 *
     839 * Return: available frame size
    818840 */
    819841static inline snd_pcm_sframes_t snd_pcm_capture_hw_avail(struct snd_pcm_runtime *runtime)
     
    955977 * params_channels - Get the number of channels from the hw params
    956978 * @p: hw params
     979 *
     980 * Return: the number of channels
    957981 */
    958982static inline unsigned int params_channels(const struct snd_pcm_hw_params *p)
     
    964988 * params_rate - Get the sample rate from the hw params
    965989 * @p: hw params
     990 *
     991 * Return: the sample rate
    966992 */
    967993static inline unsigned int params_rate(const struct snd_pcm_hw_params *p)
     
    973999 * params_period_size - Get the period size (in frames) from the hw params
    9741000 * @p: hw params
     1001 *
     1002 * Return: the period size in frames
    9751003 */
    9761004static inline unsigned int params_period_size(const struct snd_pcm_hw_params *p)
     
    9821010 * params_periods - Get the number of periods from the hw params
    9831011 * @p: hw params
     1012 *
     1013 * Return: the number of periods
    9841014 */
    9851015static inline unsigned int params_periods(const struct snd_pcm_hw_params *p)
     
    9911021 * params_buffer_size - Get the buffer size (in frames) from the hw params
    9921022 * @p: hw params
     1023 *
     1024 * Return: the buffer size in frames
    9931025 */
    9941026static inline unsigned int params_buffer_size(const struct snd_pcm_hw_params *p)
     
    10001032 * params_buffer_bytes - Get the buffer size (in bytes) from the hw params
    10011033 * @p: hw params
     1034 *
     1035 * Return: the buffer size in bytes
    10021036 */
    10031037static inline unsigned int params_buffer_bytes(const struct snd_pcm_hw_params *p)
     
    12621296 * allocation of a larger buffer unlike the standard one.
    12631297 * The function may return -ENOMEM error, hence the caller must check it.
     1298 *
     1299 * Return: zero if successful, or a negative error code
    12641300 */
    12651301static inline int __must_check
     
    12801316 * all substream.  If any of allocation fails, it returns -ENOMEM, hence the
    12811317 * caller must check the return value.
     1318 *
     1319 * Return: zero if successful, or a negative error code
    12821320 */
    12831321static inline int __must_check
     
    13361374 * @substream: PCM substream
    13371375 * @ofs: byte offset
     1376 *
     1377 * Return: DMA address
    13381378 */
    13391379static inline dma_addr_t
     
    13491389 * @ofs: byte offset
    13501390 * @size: byte size to examine
     1391 *
     1392 * Return: chunk size
    13511393 */
    13521394static inline unsigned int
     
    14141456
    14151457/**
    1416  * snd_pcm_stream_str - Get a string naming the direction of a stream
    1417  * @substream: the pcm substream instance
    1418  *
    1419  * Return: A string naming the direction of the stream.
    1420  */
    1421 static inline const char *snd_pcm_stream_str(struct snd_pcm_substream *substream)
    1422 {
    1423         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
     1458 * snd_pcm_direction_name - Get a string naming the direction of a stream
     1459 * @direction: Stream's direction, one of SNDRV_PCM_STREAM_XXX
     1460 *
     1461 * Returns a string naming the direction of the stream.
     1462 */
     1463static inline const char *snd_pcm_direction_name(int direction)
     1464{
     1465        if (direction == SNDRV_PCM_STREAM_PLAYBACK)
    14241466                return "Playback";
    14251467        else
    14261468                return "Capture";
     1469}
     1470
     1471/**
     1472 * snd_pcm_stream_str - Get a string naming the direction of a stream
     1473 * @substream: the pcm substream instance
     1474 *
     1475 * Return: A string naming the direction of the stream.
     1476 */
     1477static inline const char *snd_pcm_stream_str(struct snd_pcm_substream *substream)
     1478{
     1479        return snd_pcm_direction_name(substream->stream);
    14271480}
    14281481
     
    14511504 * @info: chmap information
    14521505 * @idx: the substream number index
     1506 *
     1507 * Return: the matched PCM substream, or NULL if not found
    14531508 */
    14541509static inline struct snd_pcm_substream *
     
    14811536 * pcm_format_to_bits - Strong-typed conversion of pcm_format to bitwise
    14821537 * @pcm_format: PCM format
     1538 *
     1539 * Return: 64bit mask corresponding to the given PCM format
    14831540 */
    14841541static inline u64 pcm_format_to_bits(snd_pcm_format_t pcm_format)
  • GPL/branches/uniaud32-exp/alsa-kernel/include/sound/rawmidi.h

    r710 r750  
    6464        int buffer_ref;         /* buffer reference count */
    6565        /* misc */
    66         spinlock_t lock;
    6766        wait_queue_head_t sleep;
    6867        /* event handler (new bytes, input only) */
     
    8685        int use_count;                  /* use counter (for output) */
    8786        size_t bytes;
     87        spinlock_t lock;
    8888        struct snd_rawmidi *rmidi;
    8989        struct snd_rawmidi_str *pstr;
     
    157157int snd_rawmidi_transmit(struct snd_rawmidi_substream *substream,
    158158                         unsigned char *buffer, int count);
    159 int __snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
    160                               unsigned char *buffer, int count);
    161 int __snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream,
    162                                int count);
    163159int snd_rawmidi_proceed(struct snd_rawmidi_substream *substream);
    164160
  • GPL/branches/uniaud32-exp/alsa-kernel/include/sound/simple_card_utils.h

    r738 r750  
    5252        int codecs;
    5353        int platforms;
    54         int c2c;
    5554};
    5655
     
    6564                struct asoc_simple_data adata;
    6665                struct snd_soc_codec_conf *codec_conf;
    67                 struct snd_soc_pcm_stream *c2c_conf;
    6866                struct prop_nums num;
    6967                unsigned int mclk_fs;
     
    7674        struct snd_soc_dai_link_component dummy;
    7775        struct snd_soc_codec_conf *codec_conf;
    78         struct snd_soc_pcm_stream *c2c_conf;
    7976        struct gpio_desc *pa_gpio;
    8077        const struct snd_soc_ops *ops;
     
    174171                                  int is_single_links);
    175172
    176 int asoc_simple_clean_reference(struct snd_soc_card *card);
     173void asoc_simple_clean_reference(struct snd_soc_card *card);
    177174
    178175void asoc_simple_convert_fixup(struct asoc_simple_data *data,
  • GPL/branches/uniaud32-exp/alsa-kernel/include/sound/soc-acpi-intel-match.h

    r692 r750  
    3131extern struct snd_soc_acpi_mach snd_soc_acpi_intel_jsl_machines[];
    3232extern struct snd_soc_acpi_mach snd_soc_acpi_intel_adl_machines[];
     33extern struct snd_soc_acpi_mach snd_soc_acpi_intel_mtl_machines[];
    3334
    3435extern struct snd_soc_acpi_mach snd_soc_acpi_intel_cnl_sdw_machines[];
     
    3839extern struct snd_soc_acpi_mach snd_soc_acpi_intel_tgl_sdw_machines[];
    3940extern struct snd_soc_acpi_mach snd_soc_acpi_intel_adl_sdw_machines[];
     41extern struct snd_soc_acpi_mach snd_soc_acpi_intel_mtl_sdw_machines[];
    4042
    4143/*
  • GPL/branches/uniaud32-exp/alsa-kernel/include/sound/soc-component.h

    r739 r750  
    180180         */
    181181        unsigned int endianness:1;
    182         unsigned int non_legacy_dai_naming:1;
     182        unsigned int legacy_dai_naming:1;
    183183
    184184        /* this component uses topology and ignore machine driver FEs */
     
    347347{
    348348        return regcache_sync(component->regmap);
    349 }
    350 
    351 static inline int snd_soc_component_is_codec(struct snd_soc_component *component)
    352 {
    353         return component->driver->non_legacy_dai_naming;
    354349}
    355350
  • GPL/branches/uniaud32-exp/alsa-kernel/include/sound/soc-dai.h

    r737 r750  
    124124#define SND_SOC_DAIFMT_CBM_CFS          SND_SOC_DAIFMT_CBP_CFC
    125125#define SND_SOC_DAIFMT_CBS_CFS          SND_SOC_DAIFMT_CBC_CFC
     126
     127/* when passed to set_fmt directly indicate if the device is provider or consumer */
     128#define SND_SOC_DAIFMT_BP_FP            SND_SOC_DAIFMT_CBP_CFP
     129#define SND_SOC_DAIFMT_BC_FP            SND_SOC_DAIFMT_CBC_CFP
     130#define SND_SOC_DAIFMT_BP_FC            SND_SOC_DAIFMT_CBP_CFC
     131#define SND_SOC_DAIFMT_BC_FC            SND_SOC_DAIFMT_CBC_CFC
    126132
    127133/* Describes the possible PCM format */
  • GPL/branches/uniaud32-exp/alsa-kernel/include/sound/soc.h

    r739 r750  
    137137        .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
    138138                                          max, invert, 0) }
     139#define SOC_DOUBLE_SX_TLV(xname, xreg, shift_left, shift_right, xmin, xmax, tlv_array) \
     140{       .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
     141        .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
     142        SNDRV_CTL_ELEM_ACCESS_READWRITE, \
     143        .tlv.p  = (tlv_array), \
     144        .info = snd_soc_info_volsw_sx, \
     145        .get = snd_soc_get_volsw_sx, \
     146        .put = snd_soc_put_volsw_sx, \
     147        .private_value = (unsigned long)&(struct soc_mixer_control) \
     148                {.reg = xreg, .rreg = xreg, \
     149                .shift = shift_left, .rshift = shift_right, \
     150                .max = xmax, .min = xmin} }
    139151#define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \
    140152{       .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
     
    415427
    416428int snd_soc_register_card(struct snd_soc_card *card);
    417 int snd_soc_unregister_card(struct snd_soc_card *card);
     429void snd_soc_unregister_card(struct snd_soc_card *card);
    418430int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card);
    419431#ifdef CONFIG_PM_SLEEP
     
    915927        int (*probe)(struct snd_soc_card *card);
    916928        int (*late_probe)(struct snd_soc_card *card);
     929        void (*fixup_controls)(struct snd_soc_card *card);
    917930        int (*remove)(struct snd_soc_card *card);
    918931
  • GPL/branches/uniaud32-exp/alsa-kernel/include/sound/sof.h

    r739 r750  
    139139        struct snd_sof_dsp_ops *ops;
    140140        int (*ops_init)(struct snd_sof_dev *sdev);
     141        void (*ops_free)(struct snd_sof_dev *sdev);
    141142};
    142143
  • GPL/branches/uniaud32-exp/alsa-kernel/include/sound/version.h

    r749 r750  
    11/* include/version.h */
    2 #define CONFIG_SND_VERSION "5.19.12"
     2#define CONFIG_SND_VERSION "6.0"
    33#define CONFIG_SND_DATE ""
  • GPL/branches/uniaud32-exp/alsa-kernel/include/uapi/sound/asound.h

    r737 r750  
    11501150        unsigned int length;    /* in bytes aligned to 4 */
    11511151#ifndef TARGET_OS2
    1152         unsigned int tlv[0];    /* first TLV */
     1152        unsigned int tlv[];     /* first TLV */
    11531153#else
    11541154        unsigned int tlv[1];    /* first TLV */
  • GPL/branches/uniaud32-exp/alsa-kernel/include/uapi/sound/compress_offload.h

    r629 r750  
    124124
    125125/**
    126  * enum sndrv_compress_encoder
     126 * enum sndrv_compress_encoder - encoder metadata key
    127127 * @SNDRV_COMPRESS_ENCODER_PADDING: no of samples appended by the encoder at the
    128128 * end of the track
  • GPL/branches/uniaud32-exp/alsa-kernel/include/uapi/sound/compress_params.h

    r629 r750  
    251251
    252252/**
    253  * struct snd_enc_vorbis
     253 * struct snd_enc_vorbis - Vorbis encoder parameters
    254254 * @quality: Sets encoding quality to n, between -1 (low) and 10 (high).
    255255 * In the default mode of operation, the quality level is 3.
     
    280280
    281281/**
    282  * struct snd_enc_real
     282 * struct snd_enc_real - RealAudio encoder parameters
    283283 * @quant_bits: number of coupling quantization bits in the stream
    284284 * @start_region: coupling start region in the stream
     
    295295
    296296/**
    297  * struct snd_enc_flac
     297 * struct snd_enc_flac - FLAC encoder parameters
    298298 * @num: serial number, valid only for OGG formats
    299299 *      needs to be set by application
  • GPL/branches/uniaud32-exp/alsa-kernel/pci/emu10k1/memory.c

    r697 r750  
    325325        }
    326326        /* fill buffer addresses but pointers are not stored so that
    327          * snd_free_pci_page() is not called in in synth_free()
     327         * snd_free_pci_page() is not called in synth_free()
    328328         */
    329329        idx = 0;
  • GPL/branches/uniaud32-exp/alsa-kernel/pci/ens1370.c

    r737 r750  
    99 * for ens1371 only ( FIXME )
    1010 * derived from cs4281.c, atiixp.c and via82xx.c
    11  * using http://www.alsa-project.org/~tiwai/writing-an-alsa-driver/
     11 * using https://www.kernel.org/doc/html/latest/sound/kernel-api/writing-an-alsa-driver.html
    1212 * by Kurt J. Bosch
    1313 */
  • GPL/branches/uniaud32-exp/alsa-kernel/pci/hda/hda_bind.c

    r749 r750  
    253253        hda_nid_t nid;
    254254
     255        /*
     256         * For ASoC users, if snd_hda_hdmi_codec module is denylisted and any
     257         * event causes i915 enumeration to fail, ->wcaps remains uninitialized.
     258         */
     259        if (!codec->wcaps)
     260                return true;
     261
    255262        for_each_hda_codec_node(nid, codec) {
    256263                unsigned int wcaps = get_wcaps(codec, nid);
  • GPL/branches/uniaud32-exp/alsa-kernel/pci/hda/hda_codec.c

    r739 r750  
    785785void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec)
    786786{
    787         if (codec->registered) {
     787        if (codec->core.registered) {
    788788                /* pm_runtime_put() is called in snd_hdac_device_exit() */
    789789                pm_runtime_get_noresume(hda_codec_dev(codec));
    790790                pm_runtime_disable(hda_codec_dev(codec));
    791                 codec->registered = 0;
     791                codec->core.registered = 0;
    792792        }
    793793
     
    838838void snd_hda_codec_register(struct hda_codec *codec)
    839839{
    840         if (codec->registered)
     840        if (codec->core.registered)
    841841                return;
    842842        if (device_is_registered(hda_codec_dev(codec))) {
     
    845845                /* it was powered up in snd_hda_codec_new(), now all done */
    846846                snd_hda_power_down(codec);
    847                 codec->registered = 1;
     847                codec->core.registered = 1;
    848848        }
    849849}
     
    963963{
    964964        struct hda_codec *codec;
     965        int ret;
    965966
    966967        codec = snd_hda_codec_device_init(bus, codec_addr, "hdaudioC%dD%d",
     
    970971        *codecp = codec;
    971972
    972         return snd_hda_codec_device_new(bus, card, codec_addr, *codecp, true);
     973        ret = snd_hda_codec_device_new(bus, card, codec_addr, *codecp, true);
     974        if (ret)
     975                put_device(hda_codec_dev(*codecp));
     976
     977        return ret;
    973978}
    974979EXPORT_SYMBOL_GPL(snd_hda_codec_new);
     
    10251030        if (codec->bus->modelname) {
    10261031                codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL);
    1027                 if (!codec->modelname) {
    1028                         err = -ENOMEM;
    1029                         goto error;
    1030                 }
     1032                if (!codec->modelname)
     1033                        return -ENOMEM;
    10311034        }
    10321035
     
    10341037        err = read_widget_caps(codec, fg);
    10351038        if (err < 0)
    1036                 goto error;
     1039                return err;
    10371040        err = read_pin_defaults(codec);
    10381041        if (err < 0)
    1039                 goto error;
     1042                return err;
    10401043
    10411044        /* power-up all before initialization */
     
    10551058                err = snd_device_new(card, SNDRV_DEV_CODEC, codec, &dev_ops);
    10561059                if (err < 0)
    1057                         goto error;
    1058         }
    1059 
     1060                        return err;
     1061        }
     1062
     1063#ifdef CONFIG_PM
    10601064        /* PM runtime needs to be enabled later after binding codec */
    1061         pm_runtime_forbid(&codec->core.dev);
    1062 
    1063         return 0;
    1064 
    1065  error:
    1066         put_device(hda_codec_dev(codec));
    1067         return err;
     1065        if (codec->core.dev.power.runtime_auto)
     1066                pm_runtime_forbid(&codec->core.dev);
     1067        else
     1068                /* Keep the usage_count consistent across subsequent probing */
     1069                pm_runtime_get_noresume(&codec->core.dev);
     1070#endif
     1071
     1072        return 0;
    10681073}
    10691074EXPORT_SYMBOL_GPL(snd_hda_codec_device_new);
     
    30673072
    30683073        /* Skip the shutdown if codec is not registered */
    3069         if (!codec->registered)
     3074        if (!codec->core.registered)
    30703075                return;
    30713076
  • GPL/branches/uniaud32-exp/alsa-kernel/pci/hda/hda_component2.h

    r737 r750  
    1515        struct device *dev;
    1616        char name[HDA_MAX_NAME_SIZE];
     17        struct hda_codec *codec;
    1718        void (*playback_hook)(struct device *dev, int action);
    18         int (*set_channel_map)(struct device *dev, unsigned int rx_num, unsigned int *rx_slot,
    19                                 unsigned int tx_num, unsigned int *tx_slot);
     19        int (*suspend_hook)(struct device *dev);
     20        int (*resume_hook)(struct device *dev);
    2021};
  • GPL/branches/uniaud32-exp/alsa-kernel/pci/hda/hda_sysfs.c

    r629 r750  
    3434        struct hda_codec *codec = dev_get_drvdata(dev);
    3535        snd_hda_update_power_acct(codec);
    36         return sprintf(buf, "%u\n", jiffies_to_msecs(codec->power_on_acct));
     36        return sysfs_emit(buf, "%u\n", jiffies_to_msecs(codec->power_on_acct));
    3737}
    3838
     
    4343        struct hda_codec *codec = dev_get_drvdata(dev);
    4444        snd_hda_update_power_acct(codec);
    45         return sprintf(buf, "%u\n", jiffies_to_msecs(codec->power_off_acct));
     45        return sysfs_emit(buf, "%u\n", jiffies_to_msecs(codec->power_off_acct));
    4646}
    4747
     
    5656{                                                               \
    5757        struct hda_codec *codec = dev_get_drvdata(dev);         \
    58         return sprintf(buf, "0x%x\n", codec->field);            \
     58        return sysfs_emit(buf, "0x%x\n", codec->field);         \
    5959}
    6060
     
    6565{                                                               \
    6666        struct hda_codec *codec = dev_get_drvdata(dev);         \
    67         return sprintf(buf, "%s\n",                             \
    68                        codec->field ? codec->field : "");       \
     67        return sysfs_emit(buf, "%s\n",                          \
     68                          codec->field ? codec->field : "");    \
    6969}
    7070
     
    8686        mutex_lock(&codec->user_mutex);
    8787        snd_array_for_each(list, i, pin) {
    88                 len += sprintf(buf + len, "0x%02x 0x%08x\n",
    89                                pin->nid, pin->cfg);
     88                len += sysfs_emit_at(buf, len, "0x%02x 0x%08x\n",
     89                                     pin->nid, pin->cfg);
    9090        }
    9191        mutex_unlock(&codec->user_mutex);
     
    223223        mutex_lock(&codec->user_mutex);
    224224        snd_array_for_each(&codec->init_verbs, i, v) {
    225                 len += scnprintf(buf + len, PAGE_SIZE - len,
    226                                 "0x%02x 0x%03x 0x%04x\n",
    227                                 v->nid, v->verb, v->param);
     225                len += sysfs_emit_at(buf, len, "0x%02x 0x%03x 0x%04x\n",
     226                                     v->nid, v->verb, v->param);
    228227        }
    229228        mutex_unlock(&codec->user_mutex);
     
    273272        mutex_lock(&codec->user_mutex);
    274273        snd_array_for_each(&codec->hints, i, hint) {
    275                 len += scnprintf(buf + len, PAGE_SIZE - len,
    276                                 "%s = %s\n", hint->key, hint->val);
     274                len += sysfs_emit_at(buf, len, "%s = %s\n",
     275                                    hint->key, hint->val);
    277276        }
    278277        mutex_unlock(&codec->user_mutex);
  • GPL/branches/uniaud32-exp/alsa-kernel/pci/hda/patch_hdmi.c

    r749 r750  
    12911291        per_pin = get_pin(spec, pin_idx);
    12921292        per_pin->cvt_nid = per_cvt->cvt_nid;
     1293        per_pin->silent_stream = false;
    12931294        hinfo->nid = per_cvt->cvt_nid;
    12941295
  • GPL/branches/uniaud32-exp/alsa-kernel/pci/hda/patch_realtek.c

    r749 r750  
    37553755        snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
    37563756
     3757        for (i = 0; i < HDA_MAX_COMPONENTS; i++)
     3758                if (spec->comps[i].resume_hook)
     3759                        spec->comps[i].resume_hook(spec->comps[i].dev);
     3760
    37573761        return 0;
    37583762
     
    46764680{
    46774681        //NOT_USED struct alc_spec *spec = codec->spec;
     4682        int i;
    46784683
    46794684#ifndef TARGET_OS2
    46804685        if (spec->has_alc5505_dsp)
    46814686                alc5505_dsp_suspend(codec);
     4687
     4688        for (i = 0; i < HDA_MAX_COMPONENTS; i++)
     4689                if (spec->comps[i].suspend_hook)
     4690                        spec->comps[i].suspend_hook(spec->comps[i].dev);
    46824691#endif
    46834692        return alc_suspend(codec);
     
    46874696{
    46884697        struct alc_spec *spec = codec->spec;
     4698        int i;
    46894699
    46904700        if (spec->codec_variant == ALC269_TYPE_ALC269VB)
     
    73547364        struct hda_codec *cdc = dev_to_hda_codec(dev);
    73557365        struct alc_spec *spec = cdc->spec;
    7356 
    7357         return component_bind_all(dev, spec->comps);
     7366        int ret, i;
     7367
     7368        ret = component_bind_all(dev, spec->comps);
     7369        if (ret)
     7370                return ret;
     7371
     7372        if (snd_hdac_is_power_on(&cdc->core)) {
     7373                codec_dbg(cdc, "Resuming after bind.\n");
     7374                for (i = 0; i < HDA_MAX_COMPONENTS; i++)
     7375                        if (spec->comps[i].resume_hook)
     7376                                spec->comps[i].resume_hook(spec->comps[i].dev);
     7377        }
     7378
     7379        return 0;
    73587380}
    73597381
     
    73987420                        if (!name)
    73997421                                return;
     7422                        spec->comps[i].codec = cdc;
    74007423                        component_match_add(dev, &spec->match, component_compare_dev_name, name);
    74017424                }
     
    74287451{
    74297452        cs35l41_generic_fixup(cdc, action, "i2c", "CLSA0100", 2);
     7453}
     7454
     7455static void alc287_fixup_legion_16ithg6_speakers(struct hda_codec *cdc, const struct hda_fixup *fix,
     7456                                                 int action)
     7457{
     7458        cs35l41_generic_fixup(cdc, action, "i2c", "CLSA0101", 2);
    74307459}
    74317460
     
    78087837        ALC285_FIXUP_HP_SPEAKERS_MICMUTE_LED,
    78097838        ALC295_FIXUP_FRAMEWORK_LAPTOP_MIC_NO_PRESENCE,
     7839        ALC287_FIXUP_LEGION_16ITHG6,
    78107840        ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK,
    78117841        ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN,
     
    1000810038                .chained = true,
    1000910039                .chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC
     10040        },
     10041        [ALC287_FIXUP_LEGION_16ITHG6] = {
     10042                .type = HDA_FIXUP_FUNC,
     10043                .v.func = alc287_fixup_legion_16ithg6_speakers,
    1001010044        },
    1001110045        [ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK] = {
     
    1055910593        SND_PCI_QUIRK(0x17aa, 0x3852, "Lenovo Yoga 7 14ITL5", ALC287_FIXUP_YOGA7_14ITL_SPEAKERS),
    1056010594        SND_PCI_QUIRK(0x17aa, 0x3853, "Lenovo Yoga 7 15ITL5", ALC287_FIXUP_YOGA7_14ITL_SPEAKERS),
     10595        SND_PCI_QUIRK(0x17aa, 0x3855, "Legion 7 16ITHG6", ALC287_FIXUP_LEGION_16ITHG6),
     10596        SND_PCI_QUIRK(0x17aa, 0x3869, "Lenovo Yoga7 14IAL7", ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN),
    1056110597        SND_PCI_QUIRK(0x17aa, 0x3902, "Lenovo E50-80", ALC269_FIXUP_DMIC_THINKPAD_ACPI),
    1056210598        SND_PCI_QUIRK(0x17aa, 0x3977, "IdeaPad S210", ALC283_FIXUP_INT_MIC),
  • GPL/branches/uniaud32-exp/include/linux/pm.h

    r711 r750  
    247247        struct list_head        entry;
    248248        enum rpm_status         runtime_status;
     249        unsigned int            runtime_auto:1;
    249250};
    250251
  • GPL/branches/uniaud32-exp/lib32/misc.c

    r737 r750  
    4040#include <linux/firmware.h>
    4141#include <linux/ctype.h>
     42#include <linux/math64.h>
    4243#include <dbgos2.h>
    4344
     
    823824}
    824825EXPORT_SYMBOL(sysfs_streq);
     826
     827u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
     828{
     829        u32 high = divisor >> 32;
     830        u64 quot;
     831
     832        if (high == 0) {
     833                u32 rem32;
     834                quot = div_u64_rem(dividend, divisor, &rem32);
     835                *remainder = rem32;
     836        } else {
     837                int n = fls(high);
     838                quot = div_u64(dividend >> n, divisor >> n);
     839
     840                if (quot != 0)
     841                        quot--;
     842
     843                *remainder = dividend - quot * divisor;
     844                if (*remainder >= divisor) {
     845                        quot++;
     846                        *remainder -= divisor;
     847                }
     848        }
     849
     850        return quot;
     851}
     852
     853/**
     854 * memset32() - Fill a memory area with a uint32_t
     855 * @s: Pointer to the start of the area.
     856 * @v: The value to fill the area with
     857 * @count: The number of values to store
     858 *
     859 * Differs from memset() in that it fills with a uint32_t instead
     860 * of a byte.  Remember that @count is the number of uint32_ts to
     861 * store, not the number of bytes.
     862 */
     863void *memset32(uint32_t *s, uint32_t v, size_t count)
     864{
     865        uint32_t *xs = s;
     866
     867        while (count--)
     868                *xs++ = v;
     869        return s;
     870}
     871EXPORT_SYMBOL(memset32);
     872
     873/**
     874 *      sysfs_emit - scnprintf equivalent, aware of PAGE_SIZE buffer.
     875 *      @buf:   start of PAGE_SIZE buffer.
     876 *      @fmt:   format
     877 *      @...:   optional arguments to @format
     878 *
     879 *
     880 * Returns number of characters written to @buf.
     881 */
     882int sysfs_emit(char *buf, const char *fmt, ...)
     883{
     884        va_list args;
     885        int len;
     886
     887#ifdef NOT_USED
     888        if (WARN(!buf || offset_in_page(buf),
     889                 "invalid sysfs_emit: buf:%p\n", buf))
     890                return 0;
     891#endif
     892
     893        va_start(args, fmt);
     894        len = vscnprintf(buf, PAGE_SIZE, fmt, args);
     895        va_end(args);
     896
     897        return len;
     898}
     899EXPORT_SYMBOL_GPL(sysfs_emit);
     900
     901/**
     902 *      sysfs_emit_at - scnprintf equivalent, aware of PAGE_SIZE buffer.
     903 *      @buf:   start of PAGE_SIZE buffer.
     904 *      @at:    offset in @buf to start write in bytes
     905 *              @at must be >= 0 && < PAGE_SIZE
     906 *      @fmt:   format
     907 *      @...:   optional arguments to @fmt
     908 *
     909 *
     910 * Returns number of characters written starting at &@buf[@at].
     911 */
     912int sysfs_emit_at(char *buf, int at, const char *fmt, ...)
     913{
     914        va_list args;
     915        int len;
     916
     917#ifdef NOT_USED
     918        if (WARN(!buf || offset_in_page(buf) || at < 0 || at >= PAGE_SIZE,
     919                 "invalid sysfs_emit_at: buf:%p at:%d\n", buf, at))
     920                return 0;
     921#endif
     922
     923        va_start(args, fmt);
     924        len = vscnprintf(buf + at, PAGE_SIZE - at, fmt, args);
     925        va_end(args);
     926
     927        return len;
     928}
     929EXPORT_SYMBOL_GPL(sysfs_emit_at);
  • GPL/branches/uniaud32-exp/lib32/vsprintf.c

    r32 r750  
    3232
    3333#include <stdarg.h>
    34 
     34#include <linux/kernel.h>
    3535
    3636
     
    366366}
    367367
     368/**
     369 * vscnprintf - Format a string and place it in a buffer
     370 * @buf: The buffer to place the result into
     371 * @size: The size of the buffer, including the trailing null space
     372 * @fmt: The format string to use
     373 * @args: Arguments for the format string
     374 *
     375 * The return value is the number of characters which have been written into
     376 * the @buf not including the trailing '\0'. If @size is == 0 the function
     377 * returns 0.
     378 *
     379 * If you're not already dealing with a va_list consider using scnprintf().
     380 *
     381 * See the vsnprintf() documentation for format string extensions over C99.
     382 */
     383int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
     384{
     385        int i;
     386
     387        if (unlikely(!size))
     388                return 0;
     389
     390        i = vsnprintf(buf, size, fmt, args);
     391
     392        if (likely(i < size))
     393                return i;
     394
     395        return size - 1;
     396}
Note: See TracChangeset for help on using the changeset viewer.