|
Last change
on this file since 692 was 679, checked in by David Azarewicz, 5 years ago |
|
Merge changes from Paul's uniaud32next branch.
|
|
File size:
998 bytes
|
| Line | |
|---|
| 1 | /* SPDX-License-Identifier: GPL-2.0 OR MIT */
|
|---|
| 2 | #ifndef __LINUX_OVERFLOW_H
|
|---|
| 3 | #define __LINUX_OVERFLOW_H
|
|---|
| 4 |
|
|---|
| 5 | #include <linux/compiler.h>
|
|---|
| 6 |
|
|---|
| 7 | /**
|
|---|
| 8 | * array_size() - Calculate size of 2-dimensional array.
|
|---|
| 9 | *
|
|---|
| 10 | * @a: dimension one
|
|---|
| 11 | * @b: dimension two
|
|---|
| 12 | *
|
|---|
| 13 | * Calculates size of 2-dimensional array: @a * @b.
|
|---|
| 14 | *
|
|---|
| 15 | * Returns: number of bytes needed to represent the array or SIZE_MAX on
|
|---|
| 16 | * overflow.
|
|---|
| 17 | */
|
|---|
| 18 | static inline __must_check size_t array_size(size_t a, size_t b)
|
|---|
| 19 | {
|
|---|
| 20 | size_t bytes;
|
|---|
| 21 |
|
|---|
| 22 | bytes = a * b;
|
|---|
| 23 |
|
|---|
| 24 | return bytes;
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | /**
|
|---|
| 28 | * array3_size() - Calculate size of 3-dimensional array.
|
|---|
| 29 | *
|
|---|
| 30 | * @a: dimension one
|
|---|
| 31 | * @b: dimension two
|
|---|
| 32 | * @c: dimension three
|
|---|
| 33 | *
|
|---|
| 34 | * Calculates size of 3-dimensional array: @a * @b * @c.
|
|---|
| 35 | *
|
|---|
| 36 | * Returns: number of bytes needed to represent the array or SIZE_MAX on
|
|---|
| 37 | * overflow.
|
|---|
| 38 | */
|
|---|
| 39 | static inline __must_check size_t array3_size(size_t a, size_t b, size_t c)
|
|---|
| 40 | {
|
|---|
| 41 | size_t bytes;
|
|---|
| 42 |
|
|---|
| 43 | bytes = a * b * c;
|
|---|
| 44 |
|
|---|
| 45 | return bytes;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | #endif /* __LINUX_OVERFLOW_H */
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.