All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denis Kenzior <denkenz@gmail.com>
To: James Prestwood <prestwoj@gmail.com>, iwd@lists.linux.dev
Subject: Re: [PATCH 04/10] wiphy: fix runtime error from bit shift
Date: Tue, 26 Jul 2022 15:57:17 -0500	[thread overview]
Message-ID: <570bd0eb-db94-f0f2-2a76-f9bdbc014b3e@gmail.com> (raw)
In-Reply-To: <20220726170920.15929-4-prestwoj@gmail.com>

Hi James,

On 7/26/22 12:09, James Prestwood wrote:
> The compiler treated the '1' as an int type which was not big enough
> to hold a bit shift of 31:
> 
> runtime error: left shift of 1 by 31 places cannot be represented in
> 		type 'int'
> 
> Instead of doing the iftype check manually, refactor
> wiphy_get_supported_iftypes by adding a subroutine which just parses
> out iftypes from a mask into a char** list. This removes the need to
> case each iftype into a string.
> ---
>   src/wiphy.c | 48 ++++++++++++++----------------------------------
>   1 file changed, 14 insertions(+), 34 deletions(-)
> 
> diff --git a/src/wiphy.c b/src/wiphy.c
> index 09b99fb2..98bd3aa4 100644
> --- a/src/wiphy.c
> +++ b/src/wiphy.c
> @@ -707,17 +707,16 @@ bool wiphy_constrain_freq_set(const struct wiphy *wiphy,
>   	return true;
>   }
>   
> -static char **wiphy_get_supported_iftypes(struct wiphy *wiphy, uint16_t mask)
> +static char **wiphy_iftype_mask_to_str(uint16_t mask)

I'm still unsure why you introduce this? Can't you use 
wiphy_get_supported_iftypes() as is?

>   {
> -	uint16_t supported_mask = wiphy->supported_iftypes & mask;
> -	char **ret = l_new(char *, __builtin_popcount(supported_mask) + 1);
> +	char **ret = l_new(char *, __builtin_popcount(mask) + 1);
>   	unsigned int i;
>   	unsigned int j;
>   
> -	for (j = 0, i = 0; i < sizeof(supported_mask) * 8; i++) {
> +	for (j = 0, i = 0; i < sizeof(mask) * 8; i++) {
>   		const char *str;
>   
> -		if (!(supported_mask & (1 << i)))
> +		if (!(mask & (1 << i)))
>   			continue;
>   
>   		str = netdev_iftype_to_string(i + 1);

Also note that since valid iftypes start at 1, we actually subtract 1 when 
parsing them for the purposes of the mask.  So get_iftypes() might need to be 
modified to do the same.

Regards,
-Denis

  reply	other threads:[~2022-07-26 21:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-26 17:09 [PATCH 01/10] manager: unregister nl80211 config watch James Prestwood
2022-07-26 17:09 ` [PATCH 02/10] test-runner: make developer mode optional James Prestwood
2022-07-26 17:09 ` [PATCH 03/10] auto-t: iwd.py: let IWD class specify developer mode James Prestwood
2022-07-26 17:09 ` [PATCH 04/10] wiphy: fix runtime error from bit shift James Prestwood
2022-07-26 20:57   ` Denis Kenzior [this message]
2022-07-27 16:00     ` James Prestwood
2022-07-26 17:09 ` [PATCH 05/10] scan: make scan_freq_set const in scan_passive James Prestwood
2022-07-26 17:09 ` [PATCH 06/10] util: make scan_freq_set_get_bands const James Prestwood
2022-07-26 17:09 ` [PATCH 07/10] util: add scan_freq_set_subtract James Prestwood
2022-07-26 17:09 ` [PATCH 08/10] wiphy: add disabled_freqs list James Prestwood
2022-07-26 17:09 ` [PATCH 09/10] wiphy: constrain scan set by disabled frequencies James Prestwood
2022-07-26 17:09 ` [PATCH 10/10] nl80211util: add nested attribute support James Prestwood
2022-07-26 20:52 ` [PATCH 01/10] manager: unregister nl80211 config watch Denis Kenzior

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=570bd0eb-db94-f0f2-2a76-f9bdbc014b3e@gmail.com \
    --to=denkenz@gmail.com \
    --cc=iwd@lists.linux.dev \
    --cc=prestwoj@gmail.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 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.