From: Marek Behun <marek.behun@nic.cz>
To: u-boot@lists.denx.de
Subject: [PATCH u-boot v3.1 01/39] regmap: fix a serious pointer casting bug
Date: Tue, 16 Mar 2021 17:51:39 +0100 [thread overview]
Message-ID: <20210316175139.4341f976@nic.cz> (raw)
In-Reply-To: <20210316163415.exylwa6iz4dq4csr@ti.com>
On Tue, 16 Mar 2021 22:04:17 +0530
Pratyush Yadav <p.yadav@ti.com> wrote:
> > + switch (map->width) {
> > + case REGMAP_SIZE_8:
> > + *valp = u.v8;
> > + break;
> > + case REGMAP_SIZE_16:
> > + *valp = u.v16;
> > + break;
> > + case REGMAP_SIZE_32:
> > + *valp = u.v32;
> > + break;
> > + case REGMAP_SIZE_64:
> > + *valp = u.v64;
> > + break;
>
> I think this should fix the problem you are trying to solve.
>
> But I see another problem with this code. What if someone wants to read
> 8 bytes? IIUC, since valp points to a uint, *valp = u.v64 will result in
> 4 bytes being truncated from the result.
>
> I see two options:
>
> - Change the uint pointer to u64 pointer and update every driver to use
> a u64 when using the regmap.
>
> - Change the uint pointer to void pointer and expect every driver to
> pass a container with exactly the required size, based on map->width.
> Update the ones that don't follow this.
>
> I prefer the latter option.
If only these two options are possible, then the first option is
better. The regmap_read function ought to be simple, so no void *
pointer.
There is another option: if a value greater than ULONG_MAX is read, the
regmap_read() function will return -ERANGE. This way this function
will remain simple. ulong is 64-bit wide on 64-bit devices, so this
only is a problem when a 64-bit wide regmap is used on a 32-bit device.
I think we should keep regmap_read() simple, and for people who use a
64-bit wide regmap on 32-bit device, there is regmap_raw_read().
But I think this problem should be solved (however we decide) in a
follow-up patch. This patch fixes the pointer casting bug, and commits
should remain atomic (fixing one thing).
Marek
next prev parent reply other threads:[~2021-03-16 16:51 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-16 12:25 [PATCH u-boot v3 00/39] U-Boot LTO (Sandbox + Some ARM boards) Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 01/39] regmap: fix a serious pointer casting bug Marek Behún
2021-03-16 13:58 ` Pratyush Yadav
2021-03-16 14:15 ` Marek Behun
2021-03-16 15:29 ` Pratyush Yadav
2021-03-16 15:52 ` Marek Behun
2021-03-16 15:07 ` [PATCH u-boot v3.1 " Marek Behún
2021-03-16 15:19 ` regmap bug fix Marek Behun
2021-03-25 0:38 ` Simon Glass
2021-03-25 0:46 ` Marek Behun
2021-03-25 2:41 ` Simon Glass
2021-03-25 12:28 ` Marek Behun
2021-03-16 16:34 ` [PATCH u-boot v3.1 01/39] regmap: fix a serious pointer casting bug Pratyush Yadav
2021-03-16 16:51 ` Marek Behun [this message]
2021-03-16 12:25 ` [PATCH u-boot v3 02/39] api: fix a potential serious bug caused by undef CONFIG_SYS_64BIT_LBA Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 03/39] checkpatch: require quotes around section name in the __section() macro Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 04/39] treewide: Convert macro and uses of __section(foo) to __section("foo") Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 05/39] compiler.h: align the __ADDRESSABLE macro with Linux' version Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 06/39] linker_lists: prepare macros to avoid code repetition Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 07/39] test/py: improve regular expression for ut subtest symbol matcher Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 08/39] linker_lists: declare lists and entries as __ADDRESSABLE for LTO Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 09/39] string: make memcpy(), memset(), memcmp() and memmove() visible " Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 10/39] efi_loader: fix warning when linking with LTO Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 11/39] efi_loader: add Sphinx doc for __efi_runtime and __efi_runtime_data Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 12/39] efi_loader: add macro for const EFI runtime data Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 13/39] efi_selftest: compiler flags for efi_selftest_miniapp_exception.o Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 14/39] lib: crc32: put the crc_table variable into efi_runtime_rodata section Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 15/39] Makefile, Makefile.spl: cosmetic change Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 16/39] build: use thin archives instead of incremental linking Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 17/39] build: support building with Link Time Optimizations Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 18/39] build: link with --build-id=none Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 19/39] sandbox: errno: avoid conflict with libc's errno Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 20/39] sandbox: use sections instead of symbols for getopt array boundaries Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 21/39] sandbox: make LTO available Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 22/39] sandbox: enable LTO by default Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 23/39] ARM: global_data: make set_gd() work for armv5 and armv6 Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 24/39] ARM: make gd a function call for LTO and set via set_gd() Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 25/39] ARM: fix LTO build for some thumb-interwork cases Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 26/39] ARM: fix LTO for imx28_xea Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 27/39] ARM: fix LTO for apf27 Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 28/39] ARM: fix LTO for keystone Marek Behún
2021-03-16 12:25 ` [PATCH u-boot v3 29/39] ARM: kona: fix clk_bsc_enable() type mismatch for LTO Marek Behún
2021-03-16 12:26 ` [PATCH u-boot v3 30/39] ARM: imx8m: fix imx_eqos_txclk_set_rate() " Marek Behún
2021-03-16 12:26 ` [PATCH u-boot v3 31/39] ARM: fix LTO for seaboard Marek Behún
2021-03-16 12:26 ` [PATCH u-boot v3 32/39] ARM: fix LTO for rockchip and samsung Marek Behún
2021-03-16 12:26 ` [PATCH u-boot v3 33/39] ARM: omap3: fix LTO for DM3730 (and possibly other omap3 boards) Marek Behún
2021-03-16 12:26 ` [PATCH u-boot v3 34/39] armv8: SPL: discard relocation information Marek Behún
2021-03-16 12:26 ` [PATCH u-boot v3 35/39] ata: ahci: fix ahci_link_up() type mismatch for LTO Marek Behún
2021-03-16 12:26 ` [PATCH u-boot v3 36/39] ARM: make LTO available Marek Behún
2021-03-16 12:26 ` [PATCH u-boot v3 37/39] ARM: don't use -ffunction-sections/-fdata-sections with LTO build Marek Behún
2021-03-16 12:26 ` [PATCH u-boot v3 38/39] ARM: don't use --gc-sections with LTO when using private libgcc Marek Behún
2021-03-16 12:26 ` [PATCH u-boot v3 39/39] ARM: enable LTO for some boards Marek Behún
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=20210316175139.4341f976@nic.cz \
--to=marek.behun@nic.cz \
--cc=u-boot@lists.denx.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.