hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/sound/soc/soc-ops.c
....@@ -63,11 +63,8 @@
6363 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
6464 unsigned int val, item;
6565 unsigned int reg_val;
66
- int ret;
6766
68
- ret = snd_soc_component_read(component, e->reg, &reg_val);
69
- if (ret)
70
- return ret;
67
+ reg_val = snd_soc_component_read(component, e->reg);
7168 val = (reg_val >> e->shift_l) & e->mask;
7269 item = snd_soc_enum_val_to_item(e, val);
7370 ucontrol->value.enumerated.item[0] = item;
....@@ -136,10 +133,7 @@
136133 int ret;
137134 unsigned int val;
138135
139
- ret = snd_soc_component_read(component, reg, &val);
140
- if (ret < 0)
141
- return ret;
142
-
136
+ val = snd_soc_component_read(component, reg);
143137 val = (val >> shift) & mask;
144138
145139 if (!sign_bit) {
....@@ -323,7 +317,7 @@
323317 mask = BIT(sign_bit + 1) - 1;
324318
325319 val = ucontrol->value.integer.value[0];
326
- if (mc->platform_max && val > mc->platform_max)
320
+ if (mc->platform_max && ((int)val + min) > mc->platform_max)
327321 return -EINVAL;
328322 if (val > max - min)
329323 return -EINVAL;
....@@ -336,7 +330,7 @@
336330 val = val << shift;
337331 if (snd_soc_volsw_is_stereo(mc)) {
338332 val2 = ucontrol->value.integer.value[1];
339
- if (mc->platform_max && val2 > mc->platform_max)
333
+ if (mc->platform_max && ((int)val2 + min) > mc->platform_max)
340334 return -EINVAL;
341335 if (val2 > max - min)
342336 return -EINVAL;
....@@ -395,19 +389,12 @@
395389 int min = mc->min;
396390 unsigned int mask = (1U << (fls(min + max) - 1)) - 1;
397391 unsigned int val;
398
- int ret;
399392
400
- ret = snd_soc_component_read(component, reg, &val);
401
- if (ret < 0)
402
- return ret;
403
-
393
+ val = snd_soc_component_read(component, reg);
404394 ucontrol->value.integer.value[0] = ((val >> shift) - min) & mask;
405395
406396 if (snd_soc_volsw_is_stereo(mc)) {
407
- ret = snd_soc_component_read(component, reg2, &val);
408
- if (ret < 0)
409
- return ret;
410
-
397
+ val = snd_soc_component_read(component, reg2);
411398 val = ((val >> rshift) - min) & mask;
412399 ucontrol->value.integer.value[1] = val;
413400 }
....@@ -445,7 +432,7 @@
445432 val = ucontrol->value.integer.value[0];
446433 if (mc->platform_max && val > mc->platform_max)
447434 return -EINVAL;
448
- if (val > max - min)
435
+ if (val > max)
449436 return -EINVAL;
450437 if (val < 0)
451438 return -EINVAL;
....@@ -458,8 +445,15 @@
458445 return err;
459446
460447 if (snd_soc_volsw_is_stereo(mc)) {
448
+ val2 = ucontrol->value.integer.value[1];
449
+
450
+ if (mc->platform_max && val2 > mc->platform_max)
451
+ return -EINVAL;
452
+ if (val2 > max)
453
+ return -EINVAL;
454
+
461455 val_mask = mask << rshift;
462
- val2 = (ucontrol->value.integer.value[1] + min) & mask;
456
+ val2 = (val2 + min) & mask;
463457 val2 = val2 << rshift;
464458
465459 err = snd_soc_component_update_bits(component, reg2, val_mask,
....@@ -523,7 +517,15 @@
523517 unsigned int mask = (1 << fls(max)) - 1;
524518 unsigned int invert = mc->invert;
525519 unsigned int val, val_mask;
526
- int err, ret;
520
+ int err, ret, tmp;
521
+
522
+ tmp = ucontrol->value.integer.value[0];
523
+ if (tmp < 0)
524
+ return -EINVAL;
525
+ if (mc->platform_max && tmp > mc->platform_max)
526
+ return -EINVAL;
527
+ if (tmp > mc->max - mc->min)
528
+ return -EINVAL;
527529
528530 if (invert)
529531 val = (max - ucontrol->value.integer.value[0]) & mask;
....@@ -538,6 +540,14 @@
538540 ret = err;
539541
540542 if (snd_soc_volsw_is_stereo(mc)) {
543
+ tmp = ucontrol->value.integer.value[1];
544
+ if (tmp < 0)
545
+ return -EINVAL;
546
+ if (mc->platform_max && tmp > mc->platform_max)
547
+ return -EINVAL;
548
+ if (tmp > mc->max - mc->min)
549
+ return -EINVAL;
550
+
541551 if (invert)
542552 val = (max - ucontrol->value.integer.value[1]) & mask;
543553 else
....@@ -580,12 +590,8 @@
580590 unsigned int mask = (1 << fls(max)) - 1;
581591 unsigned int invert = mc->invert;
582592 unsigned int val;
583
- int ret;
584593
585
- ret = snd_soc_component_read(component, reg, &val);
586
- if (ret)
587
- return ret;
588
-
594
+ val = snd_soc_component_read(component, reg);
589595 ucontrol->value.integer.value[0] = (val >> shift) & mask;
590596 if (invert)
591597 ucontrol->value.integer.value[0] =
....@@ -595,10 +601,7 @@
595601 ucontrol->value.integer.value[0] - min;
596602
597603 if (snd_soc_volsw_is_stereo(mc)) {
598
- ret = snd_soc_component_read(component, rreg, &val);
599
- if (ret)
600
- return ret;
601
-
604
+ val = snd_soc_component_read(component, rreg);
602605 ucontrol->value.integer.value[1] = (val >> shift) & mask;
603606 if (invert)
604607 ucontrol->value.integer.value[1] =
....@@ -624,23 +627,16 @@
624627 int snd_soc_limit_volume(struct snd_soc_card *card,
625628 const char *name, int max)
626629 {
627
- struct snd_card *snd_card = card->snd_card;
628630 struct snd_kcontrol *kctl;
629631 struct soc_mixer_control *mc;
630
- int found = 0;
631632 int ret = -EINVAL;
632633
633634 /* Sanity check for name and max */
634635 if (unlikely(!name || max <= 0))
635636 return -EINVAL;
636637
637
- list_for_each_entry(kctl, &snd_card->controls, list) {
638
- if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
639
- found = 1;
640
- break;
641
- }
642
- }
643
- if (found) {
638
+ kctl = snd_soc_card_get_kcontrol(card, name);
639
+ if (kctl) {
644640 mc = (struct soc_mixer_control *)kctl->private_value;
645641 if (max <= mc->max) {
646642 mc->platform_max = max;
....@@ -872,12 +868,9 @@
872868 long val = 0;
873869 unsigned int regval;
874870 unsigned int i;
875
- int ret;
876871
877872 for (i = 0; i < regcount; i++) {
878
- ret = snd_soc_component_read(component, regbase+i, &regval);
879
- if (ret)
880
- return ret;
873
+ regval = snd_soc_component_read(component, regbase+i);
881874 val |= (regval & regwmask) << (regwshift*(regcount-i-1));
882875 }
883876 val &= mask;
....@@ -959,12 +952,8 @@
959952 unsigned int mask = 1 << shift;
960953 unsigned int invert = mc->invert != 0;
961954 unsigned int val;
962
- int ret;
963955
964
- ret = snd_soc_component_read(component, reg, &val);
965
- if (ret)
966
- return ret;
967
-
956
+ val = snd_soc_component_read(component, reg);
968957 val &= mask;
969958
970959 if (shift != 0 && val != 0)