Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/include/sof/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/* Align the number to the nearest alignment value */
Copy link

Copilot AI Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The macro lacks documentation explaining the behavior when alignment is 0. Add a comment clarifying that zero alignment is treated as always aligned (returns true), which prevents division by zero in the modulo operation.

Suggested change
/* Align the number to the nearest alignment value */
/* Align the number to the nearest alignment value */
/* If alignment is zero, IS_ALIGNED returns true (treats all values as aligned).
* This prevents division by zero in the modulo operation.
*/

Copilot uses AI. Check for mistakes.
#ifndef IS_ALIGNED
#define IS_ALIGNED(size, alignment) ((size) % (alignment) == 0)
#define IS_ALIGNED(size, alignment) (!(alignment) || (size) % (alignment) == 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are using Zephyr version (included above) and this version of IS_ALIGNED wont be used (#ifndef IS_ALIGNED)

#ifdef __ZEPHYR__
#include <zephyr/sys/util.h>
#endif

btw alignment 0 is incorrect anyway so maybe this macro was called somewhere where it shouldnt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether it is incorrect or not, is a matter of definition. But apparently this change is useless on its own, so I'll close it.

#endif

/* Treat zero as a special case because it wraps around */
Expand Down
Loading