Skip to content

Commit d9ad1bd

Browse files
cladischJaroslav Kysela
authored andcommitted
[ALSA] rtctimer: optimize module parameter validation
Modules: RTC timer driver The check whether rtctimer_freq is a power of two can be done easier with a simple bit operation. Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
1 parent adf25df commit d9ad1bd

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

‎sound/core/rtctimer.c‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,11 @@ static void rtctimer_interrupt(void *private_data)
119119
*/
120120
static int __init rtctimer_init(void)
121121
{
122-
int order, err;
122+
int err;
123123
snd_timer_t *timer;
124124

125-
if (rtctimer_freq < 2 || rtctimer_freq > 8192) {
126-
snd_printk(KERN_ERR "rtctimer: invalid frequency %d\n", rtctimer_freq);
127-
return -EINVAL;
128-
}
129-
for (order = 1; rtctimer_freq > order; order <<= 1)
130-
;
131-
if (rtctimer_freq != order) {
125+
if (rtctimer_freq < 2 || rtctimer_freq > 8192 ||
126+
(rtctimer_freq & (rtctimer_freq - 1)) != 0) {
132127
snd_printk(KERN_ERR "rtctimer: invalid frequency %d\n", rtctimer_freq);
133128
return -EINVAL;
134129
}

0 commit comments

Comments
 (0)