@@ -101,11 +101,21 @@ struct opp_table *_find_opp_table(struct device *dev)
101
101
* representation in the OPP table and manage the clock configuration themselves
102
102
* in an platform specific way.
103
103
*/
104
- static bool assert_single_clk (struct opp_table * opp_table )
104
+ static bool assert_single_clk (struct opp_table * opp_table ,
105
+ unsigned int __always_unused index )
105
106
{
106
107
return !WARN_ON (opp_table -> clk_count > 1 );
107
108
}
108
109
110
+ /*
111
+ * Returns true if clock table is large enough to contain the clock index.
112
+ */
113
+ static bool assert_clk_index (struct opp_table * opp_table ,
114
+ unsigned int index )
115
+ {
116
+ return opp_table -> clk_count > index ;
117
+ }
118
+
109
119
/**
110
120
* dev_pm_opp_get_bw() - Gets the bandwidth corresponding to an opp
111
121
* @opp: opp for which bandwidth has to be returned for
@@ -524,12 +534,12 @@ static struct dev_pm_opp *_opp_table_find_key(struct opp_table *opp_table,
524
534
unsigned long (* read )(struct dev_pm_opp * opp , int index ),
525
535
bool (* compare )(struct dev_pm_opp * * opp , struct dev_pm_opp * temp_opp ,
526
536
unsigned long opp_key , unsigned long key ),
527
- bool (* assert )(struct opp_table * opp_table ))
537
+ bool (* assert )(struct opp_table * opp_table , unsigned int index ))
528
538
{
529
539
struct dev_pm_opp * temp_opp , * opp = ERR_PTR (- ERANGE );
530
540
531
541
/* Assert that the requirement is met */
532
- if (assert && !assert (opp_table ))
542
+ if (assert && !assert (opp_table , index ))
533
543
return ERR_PTR (- EINVAL );
534
544
535
545
mutex_lock (& opp_table -> lock );
@@ -557,7 +567,7 @@ _find_key(struct device *dev, unsigned long *key, int index, bool available,
557
567
unsigned long (* read )(struct dev_pm_opp * opp , int index ),
558
568
bool (* compare )(struct dev_pm_opp * * opp , struct dev_pm_opp * temp_opp ,
559
569
unsigned long opp_key , unsigned long key ),
560
- bool (* assert )(struct opp_table * opp_table ))
570
+ bool (* assert )(struct opp_table * opp_table , unsigned int index ))
561
571
{
562
572
struct opp_table * opp_table ;
563
573
struct dev_pm_opp * opp ;
@@ -580,7 +590,7 @@ _find_key(struct device *dev, unsigned long *key, int index, bool available,
580
590
static struct dev_pm_opp * _find_key_exact (struct device * dev ,
581
591
unsigned long key , int index , bool available ,
582
592
unsigned long (* read )(struct dev_pm_opp * opp , int index ),
583
- bool (* assert )(struct opp_table * opp_table ))
593
+ bool (* assert )(struct opp_table * opp_table , unsigned int index ))
584
594
{
585
595
/*
586
596
* The value of key will be updated here, but will be ignored as the
@@ -593,7 +603,7 @@ static struct dev_pm_opp *_find_key_exact(struct device *dev,
593
603
static struct dev_pm_opp * _opp_table_find_key_ceil (struct opp_table * opp_table ,
594
604
unsigned long * key , int index , bool available ,
595
605
unsigned long (* read )(struct dev_pm_opp * opp , int index ),
596
- bool (* assert )(struct opp_table * opp_table ))
606
+ bool (* assert )(struct opp_table * opp_table , unsigned int index ))
597
607
{
598
608
return _opp_table_find_key (opp_table , key , index , available , read ,
599
609
_compare_ceil , assert );
@@ -602,7 +612,7 @@ static struct dev_pm_opp *_opp_table_find_key_ceil(struct opp_table *opp_table,
602
612
static struct dev_pm_opp * _find_key_ceil (struct device * dev , unsigned long * key ,
603
613
int index , bool available ,
604
614
unsigned long (* read )(struct dev_pm_opp * opp , int index ),
605
- bool (* assert )(struct opp_table * opp_table ))
615
+ bool (* assert )(struct opp_table * opp_table , unsigned int index ))
606
616
{
607
617
return _find_key (dev , key , index , available , read , _compare_ceil ,
608
618
assert );
@@ -611,7 +621,7 @@ static struct dev_pm_opp *_find_key_ceil(struct device *dev, unsigned long *key,
611
621
static struct dev_pm_opp * _find_key_floor (struct device * dev ,
612
622
unsigned long * key , int index , bool available ,
613
623
unsigned long (* read )(struct dev_pm_opp * opp , int index ),
614
- bool (* assert )(struct opp_table * opp_table ))
624
+ bool (* assert )(struct opp_table * opp_table , unsigned int index ))
615
625
{
616
626
return _find_key (dev , key , index , available , read , _compare_floor ,
617
627
assert );
@@ -672,7 +682,8 @@ struct dev_pm_opp *
672
682
dev_pm_opp_find_freq_exact_indexed (struct device * dev , unsigned long freq ,
673
683
u32 index , bool available )
674
684
{
675
- return _find_key_exact (dev , freq , index , available , _read_freq , NULL );
685
+ return _find_key_exact (dev , freq , index , available , _read_freq ,
686
+ assert_clk_index );
676
687
}
677
688
EXPORT_SYMBOL_GPL (dev_pm_opp_find_freq_exact_indexed );
678
689
@@ -732,7 +743,8 @@ struct dev_pm_opp *
732
743
dev_pm_opp_find_freq_ceil_indexed (struct device * dev , unsigned long * freq ,
733
744
u32 index )
734
745
{
735
- return _find_key_ceil (dev , freq , index , true, _read_freq , NULL );
746
+ return _find_key_ceil (dev , freq , index , true, _read_freq ,
747
+ assert_clk_index );
736
748
}
737
749
EXPORT_SYMBOL_GPL (dev_pm_opp_find_freq_ceil_indexed );
738
750
@@ -785,7 +797,7 @@ struct dev_pm_opp *
785
797
dev_pm_opp_find_freq_floor_indexed (struct device * dev , unsigned long * freq ,
786
798
u32 index )
787
799
{
788
- return _find_key_floor (dev , freq , index , true, _read_freq , NULL );
800
+ return _find_key_floor (dev , freq , index , true, _read_freq , assert_clk_index );
789
801
}
790
802
EXPORT_SYMBOL_GPL (dev_pm_opp_find_freq_floor_indexed );
791
803
@@ -1727,7 +1739,7 @@ void dev_pm_opp_remove(struct device *dev, unsigned long freq)
1727
1739
if (IS_ERR (opp_table ))
1728
1740
return ;
1729
1741
1730
- if (!assert_single_clk (opp_table ))
1742
+ if (!assert_single_clk (opp_table , 0 ))
1731
1743
goto put_table ;
1732
1744
1733
1745
mutex_lock (& opp_table -> lock );
@@ -2079,7 +2091,7 @@ int _opp_add_v1(struct opp_table *opp_table, struct device *dev,
2079
2091
unsigned long tol , u_volt = data -> u_volt ;
2080
2092
int ret ;
2081
2093
2082
- if (!assert_single_clk (opp_table ))
2094
+ if (!assert_single_clk (opp_table , 0 ))
2083
2095
return - EINVAL ;
2084
2096
2085
2097
new_opp = _opp_allocate (opp_table );
@@ -2835,7 +2847,7 @@ static int _opp_set_availability(struct device *dev, unsigned long freq,
2835
2847
return r ;
2836
2848
}
2837
2849
2838
- if (!assert_single_clk (opp_table )) {
2850
+ if (!assert_single_clk (opp_table , 0 )) {
2839
2851
r = - EINVAL ;
2840
2852
goto put_table ;
2841
2853
}
@@ -2911,7 +2923,7 @@ int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
2911
2923
return r ;
2912
2924
}
2913
2925
2914
- if (!assert_single_clk (opp_table )) {
2926
+ if (!assert_single_clk (opp_table , 0 )) {
2915
2927
r = - EINVAL ;
2916
2928
goto put_table ;
2917
2929
}
0 commit comments