File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
drivers/hid/amd-sfh-hid/sfh1_1 Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -143,16 +143,32 @@ static int float_to_int(u32 flt32_val)
143
143
if (!exp && !mantissa )
144
144
return 0 ;
145
145
146
+ /*
147
+ * Calculate the exponent and fraction part of floating
148
+ * point representation.
149
+ */
146
150
exp -= 127 ;
147
151
if (exp < 0 ) {
148
152
exp = - exp ;
153
+ if (exp >= BITS_PER_TYPE (u32 ))
154
+ return 0 ;
149
155
zeropre = (((BIT (23 ) + mantissa ) * 100 ) >> 23 ) >> exp ;
150
156
return zeropre >= 50 ? sign : 0 ;
151
157
}
152
158
153
159
shift = 23 - exp ;
154
- flt32_val = BIT (exp ) + (mantissa >> shift );
155
- fraction = mantissa & GENMASK (shift - 1 , 0 );
160
+ if (abs (shift ) >= BITS_PER_TYPE (u32 ))
161
+ return 0 ;
162
+
163
+ if (shift < 0 ) {
164
+ shift = - shift ;
165
+ flt32_val = BIT (exp ) + (mantissa << shift );
166
+ shift = 0 ;
167
+ } else {
168
+ flt32_val = BIT (exp ) + (mantissa >> shift );
169
+ }
170
+
171
+ fraction = (shift == 0 ) ? 0 : mantissa & GENMASK (shift - 1 , 0 );
156
172
157
173
return (((fraction * 100 ) >> shift ) >= 50 ) ? sign * (flt32_val + 1 ) : sign * flt32_val ;
158
174
}
You can’t perform that action at this time.
0 commit comments