From: Kees Cook <keescook@chromium.org>
To: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: linux-kernel@vger.kernel.org,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Alexey Dobriyan <adobriyan@gmail.com>,
Jani Nikula <jani.nikula@intel.com>
Subject: Re: [PATCH 1/2] wordpart.h: Helpers for making u16/u32/u64 values
Date: Wed, 14 Feb 2024 14:09:34 -0800 [thread overview]
Message-ID: <202402141408.0E78D47@keescook> (raw)
In-Reply-To: <20240214214654.1700-1-michal.wajdeczko@intel.com>
On Wed, Feb 14, 2024 at 10:46:53PM +0100, Michal Wajdeczko wrote:
> It is quite common practice to make u16, u32 or u64 values from
> smaller words. Add simple helpers for that.
>
> Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
> ---
> v2: new macro names due to conflict with crypto/aria.h
> explicit cast and truncation everywhere (Alexey)
> moved to wordpart.h (Andy)
> ---
> Cc: Kees Cook <keescook@chromium.org>
> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Cc: Alexey Dobriyan <adobriyan@gmail.com>
> Cc: Jani Nikula <jani.nikula@intel.com>
> ---
> include/linux/wordpart.h | 32 ++++++++++++++++++++++++++++++++
> 1 file changed, 32 insertions(+)
>
> diff --git a/include/linux/wordpart.h b/include/linux/wordpart.h
> index f6f8f83b15b0..8c75a5355112 100644
> --- a/include/linux/wordpart.h
> +++ b/include/linux/wordpart.h
> @@ -31,6 +31,38 @@
> */
> #define lower_16_bits(n) ((u16)((n) & 0xffff))
>
> +/**
> + * make_u16_from_u8 - make u16 value from two u8 values
> + * @hi: value representing upper 8 bits
> + * @lo: value representing lower 8 bits
> + */
> +#define make_u16_from_u8(hi, lo) ((u16)((u16)(u8)(hi) << 8 | (u8)(lo)))
Do we want to actually do type validation here? Right now it's just
cast/truncating, which based on the version log is by design. Is silent
truncation the right thing to do?
--
Kees Cook
next prev parent reply other threads:[~2024-02-14 22:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-14 21:46 [PATCH 1/2] wordpart.h: Helpers for making u16/u32/u64 values Michal Wajdeczko
2024-02-14 21:46 ` [PATCH 2/2] drm/xe: Prefer make_u64_from_u32() over local macro Michal Wajdeczko
2024-02-14 22:09 ` Kees Cook [this message]
2024-02-15 20:40 ` [PATCH 1/2] wordpart.h: Helpers for making u16/u32/u64 values Michal Wajdeczko
2024-02-15 22:47 ` Kees Cook
2024-03-26 17:58 ` Michal Wajdeczko
2024-04-08 13:24 ` Jani Nikula
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202402141408.0E78D47@keescook \
--to=keescook@chromium.org \
--cc=adobriyan@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=jani.nikula@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.wajdeczko@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox