From: Pavel Machek <pavel@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 6/6] linux/kernel.h: sync min, max, min3, max3 macros with Linux
Date: Tue, 4 Nov 2014 20:50:13 +0100 [thread overview]
Message-ID: <20141104195013.GF13607@amd> (raw)
In-Reply-To: <1415100418-29016-7-git-send-email-yamada.m@jp.panasonic.com>
On Tue 2014-11-04 20:26:26, Masahiro Yamada wrote:
> U-Boot has never cared about the type when we get max/min of two
> values, but Linux Kernel does. This commit gets min, max, min3, max3
> macros synced with the kernel introduing type checks.
"introducing"
> Many of references of those macros must be fixed to suppress warnings.
> We have two options:
> - Use min, max, min3, max3 only when the arguments have the same type
> (or add casts to the arguments)
> - Use min_t/max_t instead with the appropriate type for the first
> argument
>
> Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Pavel Machek <pavel@denx.de>
[I guess the conversion is okay, as is, still, there are places where
code could be cleaned up afterwards...]
> - for (postdiv = 1; postdiv <= min(div, MAX_POSTDIV); postdiv++) {
> + for (postdiv = 1; postdiv <= min(div, (unsigned long)MAX_POSTDIV);
> + postdiv++) {
It might be cleaner to change MAX_POSTDIV definition to include UL?
> @@ -1838,12 +1838,18 @@ static void program_tr(unsigned long *dimm_populated,
> else
> sdram_ddr1 = false;
>
> - t_rcd_ns = max(t_rcd_ns, spd_read(iic0_dimm_addr[dimm_num], 29) >> 2);
> - t_rrd_ns = max(t_rrd_ns, spd_read(iic0_dimm_addr[dimm_num], 28) >> 2);
> - t_rp_ns = max(t_rp_ns, spd_read(iic0_dimm_addr[dimm_num], 27) >> 2);
> - t_ras_ns = max(t_ras_ns, spd_read(iic0_dimm_addr[dimm_num], 30));
> - t_rc_ns = max(t_rc_ns, spd_read(iic0_dimm_addr[dimm_num], 41));
> - t_rfc_ns = max(t_rfc_ns, spd_read(iic0_dimm_addr[dimm_num], 42));
> + t_rcd_ns = max(t_rcd_ns,
> + (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 29) >> 2);
> + t_rrd_ns = max(t_rrd_ns,
> + (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 28) >> 2);
> + t_rp_ns = max(t_rp_ns,
> + (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 27) >> 2);
> + t_ras_ns = max(t_ras_ns,
> + (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 30));
> + t_rc_ns = max(t_rc_ns,
> + (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 41));
> + t_rfc_ns = max(t_rfc_ns,
> + (unsigned long)spd_read(iic0_dimm_addr[dimm_num], 42));
> }
> }
Would it be feasible to make spd_read return unsigned long?
> diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c
> index b3d7051..b7e12ab 100644
> --- a/arch/sandbox/cpu/start.c
> +++ b/arch/sandbox/cpu/start.c
> @@ -38,7 +38,7 @@ int sandbox_early_getopt_check(void)
>
> max_arg_len = 0;
> for (i = 0; i < num_options; ++i)
> - max_arg_len = max(strlen(sb_opt[i]->flag), max_arg_len);
> + max_arg_len = max((int)strlen(sb_opt[i]->flag), max_arg_len);
> max_noarg_len = max_arg_len + 7;
>
> for (i = 0; i < num_options; ++i) {
make max_arg_len size_t?
> diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> index 623f749..677c89f 100644
> --- a/drivers/net/netconsole.c
> +++ b/drivers/net/netconsole.c
> @@ -256,7 +256,7 @@ static void nc_puts(struct stdio_dev *dev, const char *s)
>
> len = strlen(s);
> while (len) {
> - int send_len = min(len, sizeof(input_buffer));
> + int send_len = min(len, (int)sizeof(input_buffer));
> nc_send_packet(s, send_len);
> len -= send_len;
> s += send_len;
Looks like len/send_len wants to be size_t here.
Actually, I'd argue that anytime you need to explicitly cast one
argument would be good time to use _t variant... but that would mean
redoing rather big patch.
min((int) a, b) -> min_t(int, a, b).
Thanks,
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
next prev parent reply other threads:[~2014-11-04 19:50 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-04 11:26 [U-Boot] [PATCH 0/6] Collect utility macros to include/linux/kernel.h synced with Linux Masahiro Yamada
2014-11-04 11:26 ` [U-Boot] [PATCH 1/6] replace DIV_ROUND with DIV_ROUND_CLOSEST Masahiro Yamada
2014-11-04 11:26 ` [U-Boot] [PATCH 2/6] include/common.h: remove DIV_ROUND definition Masahiro Yamada
2014-11-04 11:26 ` [U-Boot] [PATCH 3/6] include: move various macros to include/linux/kernel.h Masahiro Yamada
2014-11-04 11:26 ` [U-Boot] [PATCH 4/6] linux/kernel.h: import more macros Masahiro Yamada
2014-11-04 11:26 ` [U-Boot] [PATCH 5/6] linux/kernel.h: add typechecking to roundup macro Masahiro Yamada
2014-11-04 11:26 ` [U-Boot] [PATCH 6/6] linux/kernel.h: sync min, max, min3, max3 macros with Linux Masahiro Yamada
2014-11-04 19:50 ` Pavel Machek [this message]
2014-11-05 5:06 ` Masahiro Yamada
2014-11-05 6:02 ` Marek Vasut
2014-11-05 7:48 ` Masahiro Yamada
2014-11-05 7:57 ` Marek Vasut
2014-11-05 8:12 ` Masahiro Yamada
2014-11-05 9:01 ` Marek Vasut
2014-11-06 11:59 ` Pavel Machek
2014-11-06 9:22 ` Lukasz Majewski
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=20141104195013.GF13607@amd \
--to=pavel@denx.de \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox