@@ -101,11 +101,21 @@ struct opp_table *_find_opp_table(struct device *dev)
101101 * representation in the OPP table and manage the clock configuration themselves
102102 * in an platform specific way.
103103 */
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 )
105106{
106107 return !WARN_ON (opp_table -> clk_count > 1 );
107108}
108109
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+
109119/**
110120 * dev_pm_opp_get_voltage() - Gets the voltage corresponding to an opp
111121 * @opp: opp for which voltage has to be returned for
@@ -499,12 +509,12 @@ static struct dev_pm_opp *_opp_table_find_key(struct opp_table *opp_table,
499509 unsigned long (* read )(struct dev_pm_opp * opp , int index ),
500510 bool (* compare )(struct dev_pm_opp * * opp , struct dev_pm_opp * temp_opp ,
501511 unsigned long opp_key , unsigned long key ),
502- bool (* assert )(struct opp_table * opp_table ))
512+ bool (* assert )(struct opp_table * opp_table , unsigned int index ))
503513{
504514 struct dev_pm_opp * temp_opp , * opp = ERR_PTR (- ERANGE );
505515
506516 /* Assert that the requirement is met */
507- if (assert && !assert (opp_table ))
517+ if (assert && !assert (opp_table , index ))
508518 return ERR_PTR (- EINVAL );
509519
510520 mutex_lock (& opp_table -> lock );
@@ -532,7 +542,7 @@ _find_key(struct device *dev, unsigned long *key, int index, bool available,
532542 unsigned long (* read )(struct dev_pm_opp * opp , int index ),
533543 bool (* compare )(struct dev_pm_opp * * opp , struct dev_pm_opp * temp_opp ,
534544 unsigned long opp_key , unsigned long key ),
535- bool (* assert )(struct opp_table * opp_table ))
545+ bool (* assert )(struct opp_table * opp_table , unsigned int index ))
536546{
537547 struct opp_table * opp_table ;
538548 struct dev_pm_opp * opp ;
@@ -555,7 +565,7 @@ _find_key(struct device *dev, unsigned long *key, int index, bool available,
555565static struct dev_pm_opp * _find_key_exact (struct device * dev ,
556566 unsigned long key , int index , bool available ,
557567 unsigned long (* read )(struct dev_pm_opp * opp , int index ),
558- bool (* assert )(struct opp_table * opp_table ))
568+ bool (* assert )(struct opp_table * opp_table , unsigned int index ))
559569{
560570 /*
561571 * The value of key will be updated here, but will be ignored as the
@@ -568,7 +578,7 @@ static struct dev_pm_opp *_find_key_exact(struct device *dev,
568578static struct dev_pm_opp * _opp_table_find_key_ceil (struct opp_table * opp_table ,
569579 unsigned long * key , int index , bool available ,
570580 unsigned long (* read )(struct dev_pm_opp * opp , int index ),
571- bool (* assert )(struct opp_table * opp_table ))
581+ bool (* assert )(struct opp_table * opp_table , unsigned int index ))
572582{
573583 return _opp_table_find_key (opp_table , key , index , available , read ,
574584 _compare_ceil , assert );
@@ -577,7 +587,7 @@ static struct dev_pm_opp *_opp_table_find_key_ceil(struct opp_table *opp_table,
577587static struct dev_pm_opp * _find_key_ceil (struct device * dev , unsigned long * key ,
578588 int index , bool available ,
579589 unsigned long (* read )(struct dev_pm_opp * opp , int index ),
580- bool (* assert )(struct opp_table * opp_table ))
590+ bool (* assert )(struct opp_table * opp_table , unsigned int index ))
581591{
582592 return _find_key (dev , key , index , available , read , _compare_ceil ,
583593 assert );
@@ -586,7 +596,7 @@ static struct dev_pm_opp *_find_key_ceil(struct device *dev, unsigned long *key,
586596static struct dev_pm_opp * _find_key_floor (struct device * dev ,
587597 unsigned long * key , int index , bool available ,
588598 unsigned long (* read )(struct dev_pm_opp * opp , int index ),
589- bool (* assert )(struct opp_table * opp_table ))
599+ bool (* assert )(struct opp_table * opp_table , unsigned int index ))
590600{
591601 return _find_key (dev , key , index , available , read , _compare_floor ,
592602 assert );
@@ -647,7 +657,8 @@ struct dev_pm_opp *
647657dev_pm_opp_find_freq_exact_indexed (struct device * dev , unsigned long freq ,
648658 u32 index , bool available )
649659{
650- return _find_key_exact (dev , freq , index , available , _read_freq , NULL );
660+ return _find_key_exact (dev , freq , index , available , _read_freq ,
661+ assert_clk_index );
651662}
652663EXPORT_SYMBOL_GPL (dev_pm_opp_find_freq_exact_indexed );
653664
@@ -707,7 +718,8 @@ struct dev_pm_opp *
707718dev_pm_opp_find_freq_ceil_indexed (struct device * dev , unsigned long * freq ,
708719 u32 index )
709720{
710- return _find_key_ceil (dev , freq , index , true, _read_freq , NULL );
721+ return _find_key_ceil (dev , freq , index , true, _read_freq ,
722+ assert_clk_index );
711723}
712724EXPORT_SYMBOL_GPL (dev_pm_opp_find_freq_ceil_indexed );
713725
@@ -760,7 +772,7 @@ struct dev_pm_opp *
760772dev_pm_opp_find_freq_floor_indexed (struct device * dev , unsigned long * freq ,
761773 u32 index )
762774{
763- return _find_key_floor (dev , freq , index , true, _read_freq , NULL );
775+ return _find_key_floor (dev , freq , index , true, _read_freq , assert_clk_index );
764776}
765777EXPORT_SYMBOL_GPL (dev_pm_opp_find_freq_floor_indexed );
766778
@@ -1703,7 +1715,7 @@ void dev_pm_opp_remove(struct device *dev, unsigned long freq)
17031715 if (IS_ERR (opp_table ))
17041716 return ;
17051717
1706- if (!assert_single_clk (opp_table ))
1718+ if (!assert_single_clk (opp_table , 0 ))
17071719 goto put_table ;
17081720
17091721 mutex_lock (& opp_table -> lock );
@@ -2055,7 +2067,7 @@ int _opp_add_v1(struct opp_table *opp_table, struct device *dev,
20552067 unsigned long tol , u_volt = data -> u_volt ;
20562068 int ret ;
20572069
2058- if (!assert_single_clk (opp_table ))
2070+ if (!assert_single_clk (opp_table , 0 ))
20592071 return - EINVAL ;
20602072
20612073 new_opp = _opp_allocate (opp_table );
@@ -2922,7 +2934,7 @@ static int _opp_set_availability(struct device *dev, unsigned long freq,
29222934 return r ;
29232935 }
29242936
2925- if (!assert_single_clk (opp_table )) {
2937+ if (!assert_single_clk (opp_table , 0 )) {
29262938 r = - EINVAL ;
29272939 goto put_table ;
29282940 }
@@ -2998,7 +3010,7 @@ int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
29983010 return r ;
29993011 }
30003012
3001- if (!assert_single_clk (opp_table )) {
3013+ if (!assert_single_clk (opp_table , 0 )) {
30023014 r = - EINVAL ;
30033015 goto put_table ;
30043016 }
0 commit comments