alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 01/18] ALSA: core: Use DIV_ROUND_UP() instead of open-coding it
@ 2020-12-23 17:22 Lars-Peter Clausen
  2020-12-23 17:22 ` [PATCH 02/18] ALSA: aloop: " Lars-Peter Clausen
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: Lars-Peter Clausen @ 2020-12-23 17:22 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, Lars-Peter Clausen

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: Lars-Peter Clausen <lars@metafoo.de>
---
 sound/core/control.c        | 4 ++--
 sound/core/seq/seq_memory.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/sound/core/control.c b/sound/core/control.c
index 3b44378b9dec..1571c7f7c43b 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -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;
 
-	offset = (offset + sizeof(u32) - 1) / sizeof(u32);
+	offset = DIV_ROUND_UP(offset, sizeof(u32));
 	memset32((u32 *)control->value.bytes.data + offset, pattern,
 		 sizeof(control->value) / sizeof(u32) - offset);
 }
@@ -928,7 +928,7 @@ static int sanity_check_elem_value(struct snd_card *card,
 
 	/* check whether the remaining area kept untouched */
 	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;
 	for (; offset < sizeof(control->value) / sizeof(u32); offset++, p++) {
 		if (*p != pattern) {
diff --git a/sound/core/seq/seq_memory.c b/sound/core/seq/seq_memory.c
index 65db1a7c77b7..e245bb6ba533 100644
--- a/sound/core/seq/seq_memory.c
+++ b/sound/core/seq/seq_memory.c
@@ -290,7 +290,7 @@ int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event,
 	extlen = 0;
 	if (snd_seq_ev_is_variable(event)) {
 		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)
 		return -ENOMEM;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2020-12-25  8:17 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-23 17:22 [PATCH 01/18] ALSA: core: Use DIV_ROUND_UP() instead of open-coding it Lars-Peter Clausen
2020-12-23 17:22 ` [PATCH 02/18] ALSA: aloop: " Lars-Peter Clausen
2020-12-23 17:22 ` [PATCH 03/18] ALSA: asihpi: " Lars-Peter Clausen
2020-12-23 17:22 ` [PATCH 04/18] ALSA: bt87x: " Lars-Peter Clausen
2020-12-23 17:22 ` [PATCH 05/18] ALSA: cx46xx: " Lars-Peter Clausen
2020-12-23 17:22 ` [PATCH 06/18] ALSA: ctxfi: " Lars-Peter Clausen
2020-12-23 17:22 ` [PATCH 07/18] ALSA: dummy: " Lars-Peter Clausen
2020-12-23 17:22 ` [PATCH 08/18] ALSA: emu10k1: " Lars-Peter Clausen
2020-12-23 17:22 ` [PATCH 09/18] ALSA: hda: Use DIV_ROUND_UP()/roundup() " Lars-Peter Clausen
2020-12-23 17:22 ` [PATCH 10/18] ALSA: lola: Use DIV_ROUND_UP() " Lars-Peter Clausen
2020-12-23 17:22 ` [PATCH 11/18] ALSA: usb: " Lars-Peter Clausen
2020-12-23 17:22 ` [PATCH 12/18] ALSA: vx: Use roundup() " Lars-Peter Clausen
2020-12-23 17:22 ` [PATCH 13/18] ALSA: oss: Use DIV_ROUND_CLOSEST() " Lars-Peter Clausen
2020-12-23 17:22 ` [PATCH 14/18] ALSA: sonicvibes: " Lars-Peter Clausen
2020-12-23 17:22 ` [PATCH 15/18] ALSA: trident: " Lars-Peter Clausen
2020-12-23 17:22 ` [PATCH 16/18] ALSA: ens1370: " Lars-Peter Clausen
2020-12-23 17:22 ` [PATCH 17/18] ALSA: sis7019: " Lars-Peter Clausen
2020-12-23 17:22 ` [PATCH 18/18] ALSA: maestro: " Lars-Peter Clausen
2020-12-25  8:16 ` [PATCH 01/18] ALSA: core: Use DIV_ROUND_UP() " Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).