Commit afcfbcb3 authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Takashi Iwai

ALSA: core: Use DIV_ROUND_UP() instead of open-coding it

Use DIV_ROUND_UP() instead of open-coding it. This documents intent
and makes it more clear what is going on for the casual reviewer.

Generated using the following the Coccinelle semantic patch.

// <smpl>
@@
expression x, y;
@@
-(((x) + (y) - 1) / (y))
+DIV_ROUND_UP(x, y)
// </smpl>
Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Link: https://lore.kernel.org/r/20201223172229.781-1-lars@metafoo.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent c06ccf3e
...@@ -836,7 +836,7 @@ static void fill_remaining_elem_value(struct snd_ctl_elem_value *control, ...@@ -836,7 +836,7 @@ static void fill_remaining_elem_value(struct snd_ctl_elem_value *control,
{ {
size_t offset = value_sizes[info->type] * info->count; size_t offset = value_sizes[info->type] * info->count;
offset = (offset + sizeof(u32) - 1) / sizeof(u32); offset = DIV_ROUND_UP(offset, sizeof(u32));
memset32((u32 *)control->value.bytes.data + offset, pattern, memset32((u32 *)control->value.bytes.data + offset, pattern,
sizeof(control->value) / sizeof(u32) - offset); sizeof(control->value) / sizeof(u32) - offset);
} }
...@@ -928,7 +928,7 @@ static int sanity_check_elem_value(struct snd_card *card, ...@@ -928,7 +928,7 @@ static int sanity_check_elem_value(struct snd_card *card,
/* check whether the remaining area kept untouched */ /* check whether the remaining area kept untouched */
offset = value_sizes[info->type] * info->count; offset = value_sizes[info->type] * info->count;
offset = (offset + sizeof(u32) - 1) / sizeof(u32); offset = DIV_ROUND_UP(offset, sizeof(u32));
p = (u32 *)control->value.bytes.data + offset; p = (u32 *)control->value.bytes.data + offset;
for (; offset < sizeof(control->value) / sizeof(u32); offset++, p++) { for (; offset < sizeof(control->value) / sizeof(u32); offset++, p++) {
if (*p != pattern) { if (*p != pattern) {
......
...@@ -290,7 +290,7 @@ int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event, ...@@ -290,7 +290,7 @@ int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event,
extlen = 0; extlen = 0;
if (snd_seq_ev_is_variable(event)) { if (snd_seq_ev_is_variable(event)) {
extlen = event->data.ext.len & ~SNDRV_SEQ_EXT_MASK; extlen = event->data.ext.len & ~SNDRV_SEQ_EXT_MASK;
ncells = (extlen + sizeof(struct snd_seq_event) - 1) / sizeof(struct snd_seq_event); ncells = DIV_ROUND_UP(extlen, sizeof(struct snd_seq_event));
} }
if (ncells >= pool->total_elements) if (ncells >= pool->total_elements)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment