#include <sound/info.h>
#include <sound/control.h>
+#ifdef CONFIG_SND_CTL_DEBUG
+#define CREATE_TRACE_POINTS
+#include "control_trace.h"
+#else
+#define trace_snd_ctl_put(card, kctl, iname, expected, actual)
+#endif
+
// Max allocation size for user controls.
static int max_user_ctl_alloc_size = 8 * 1024 * 1024;
module_param_named(max_user_ctl_alloc_size, max_user_ctl_alloc_size, int, 0444);
return result;
}
+#if IS_ENABLED(CONFIG_SND_CTL_DEBUG)
+
+static const char *const snd_ctl_elem_iface_names[] = {
+ [SNDRV_CTL_ELEM_IFACE_CARD] = "CARD",
+ [SNDRV_CTL_ELEM_IFACE_HWDEP] = "HWDEP",
+ [SNDRV_CTL_ELEM_IFACE_MIXER] = "MIXER",
+ [SNDRV_CTL_ELEM_IFACE_PCM] = "PCM",
+ [SNDRV_CTL_ELEM_IFACE_RAWMIDI] = "RAWMIDI",
+ [SNDRV_CTL_ELEM_IFACE_TIMER] = "TIMER",
+ [SNDRV_CTL_ELEM_IFACE_SEQUENCER] = "SEQUENCER",
+};
+
+static int snd_ctl_put_verify(struct snd_card *card, struct snd_kcontrol *kctl,
+ struct snd_ctl_elem_value *control)
+{
+ struct snd_ctl_elem_value *original = card->value_buf;
+ struct snd_ctl_elem_info info;
+ const char *iname;
+ int ret, retcmp;
+
+ memset(original, 0, sizeof(*original));
+ memset(&info, 0, sizeof(info));
+
+ ret = kctl->info(kctl, &info);
+ if (ret)
+ return ret;
+
+ ret = kctl->get(kctl, original);
+ if (ret)
+ return ret;
+
+ ret = kctl->put(kctl, control);
+ if (ret < 0)
+ return ret;
+
+ /* Sanitize the new value (control->value) before comparing. */
+ fill_remaining_elem_value(control, &info, 0);
+
+ /* With known state for both new and original, do the comparison. */
+ retcmp = memcmp(&original->value, &control->value, sizeof(original->value));
+ if (retcmp)
+ retcmp = 1;
+
+ iname = snd_ctl_elem_iface_names[kctl->id.iface];
+ trace_snd_ctl_put(&kctl->id, iname, card->number, ret, retcmp);
+
+ return ret;
+}
+
+static int snd_ctl_put(struct snd_card *card, struct snd_kcontrol *kctl,
+ struct snd_ctl_elem_value *control, unsigned int access)
+{
+ if ((access & SNDRV_CTL_ELEM_ACCESS_SKIP_CHECK) ||
+ (access & SNDRV_CTL_ELEM_ACCESS_VOLATILE))
+ return kctl->put(kctl, control);
+
+ return snd_ctl_put_verify(card, kctl, control);
+}
+#else
+static inline int snd_ctl_put(struct snd_card *card, struct snd_kcontrol *kctl,
+ struct snd_ctl_elem_value *control, unsigned int access)
+{
+ return kctl->put(kctl, control);
+}
+#endif
+
static int snd_ctl_elem_write(struct snd_card *card, struct snd_ctl_file *file,
struct snd_ctl_elem_value *control)
{
false);
}
if (!result)
- result = kctl->put(kctl, control);
+ result = snd_ctl_put(card, kctl, control, vd->access);
+
if (result < 0) {
up_write(&card->controls_rwsem);
return result;
--- /dev/null
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM snd_ctl
+
+#if !defined(_TRACE_SND_CTL_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_SND_CTL_H
+
+#include <linux/tracepoint.h>
+#include <uapi/sound/asound.h>
+
+TRACE_EVENT(snd_ctl_put,
+
+ TP_PROTO(struct snd_ctl_elem_id *id, const char *iname, unsigned int card,
+ int expected, int actual),
+
+ TP_ARGS(id, iname, card, expected, actual),
+
+ TP_STRUCT__entry(
+ __field(unsigned int, numid)
+ __string(iname, iname)
+ __string(kname, id->name)
+ __field(unsigned int, index)
+ __field(unsigned int, device)
+ __field(unsigned int, subdevice)
+ __field(unsigned int, card)
+ __field(int, expected)
+ __field(int, actual)
+ ),
+
+ TP_fast_assign(
+ __entry->numid = id->numid;
+ __assign_str(iname);
+ __assign_str(kname);
+ __entry->index = id->index;
+ __entry->device = id->device;
+ __entry->subdevice = id->subdevice;
+ __entry->card = card;
+ __entry->expected = expected;
+ __entry->actual = actual;
+ ),
+
+ TP_printk("%s: expected=%d, actual=%d for ctl numid=%d, iface=%s, name='%s', index=%d, device=%d, subdevice=%d, card=%d\n",
+ __entry->expected == __entry->actual ? "success" : "fail",
+ __entry->expected, __entry->actual, __entry->numid,
+ __get_str(iname), __get_str(kname), __entry->index,
+ __entry->device, __entry->subdevice, __entry->card)
+);
+
+#endif /* _TRACE_SND_CTL_H */
+
+/* This part must be outside protection */
+#undef TRACE_INCLUDE_PATH
+#define TRACE_INCLUDE_PATH .
+#define TRACE_INCLUDE_FILE control_trace
+#include <trace/define_trace.h>