public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH] db: fix unsigned char related warnings
Date: Fri, 3 Nov 2023 13:38:13 -0700	[thread overview]
Message-ID: <20231103203813.GG1205143@frogsfrogsfrogs> (raw)
In-Reply-To: <20231103160210.548636-1-hch@lst.de>

On Fri, Nov 03, 2023 at 05:02:10PM +0100, Christoph Hellwig wrote:
> Clean up the code in hash.c to use the normal char type for all
> high-level code, only casting to uint8_t when calling into low-level
> code.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

The problem is deeper than just this, but we gotta start somewhere...

Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  db/hash.c | 45 +++++++++++++++++++++++----------------------
>  1 file changed, 23 insertions(+), 22 deletions(-)
> 
> diff --git a/db/hash.c b/db/hash.c
> index 716da88ba..05a94f249 100644
> --- a/db/hash.c
> +++ b/db/hash.c
> @@ -65,16 +65,15 @@ hash_f(
>  	}
>  
>  	for (c = optind; c < argc; c++) {
> -		if (use_dir2_hash) {
> -			struct xfs_name	xname = {
> -				.name	= (uint8_t *)argv[c],
> -				.len	= strlen(argv[c]),
> -			};
> +		struct xfs_name	xname = {
> +			.name	= (uint8_t *)argv[c],
> +			.len	= strlen(argv[c]),
> +		};
>  
> +		if (use_dir2_hash)
>  			hashval = libxfs_dir2_hashname(mp, &xname);
> -		} else {
> -			hashval = libxfs_da_hashname(argv[c], strlen(argv[c]));
> -		}
> +		else
> +			hashval = libxfs_da_hashname(xname.name, xname.len);
>  		dbprintf("0x%x\n", hashval);
>  	}
>  
> @@ -103,7 +102,7 @@ struct name_dup {
>  	struct name_dup	*next;
>  	uint32_t	crc;
>  	uint8_t		namelen;
> -	uint8_t		name[];
> +	char		name[];
>  };
>  
>  static inline size_t
> @@ -175,7 +174,7 @@ dup_table_free(
>  static struct name_dup *
>  dup_table_find(
>  	struct dup_table	*tab,
> -	unsigned char		*name,
> +	char			*name,
>  	size_t			namelen)
>  {
>  	struct name_dup		*ent;
> @@ -197,7 +196,7 @@ dup_table_find(
>  static int
>  dup_table_store(
>  	struct dup_table	*tab,
> -	unsigned char		*name,
> +	char			*name,
>  	size_t			namelen)
>  {
>  	struct name_dup		*dup;
> @@ -209,7 +208,7 @@ dup_table_store(
>  		int		ret;
>  
>  		do {
> -			ret = find_alternate(namelen, name, seq++);
> +			ret = find_alternate(namelen, (uint8_t *)name, seq++);
>  		} while (ret == 0);
>  		if (ret < 0)
>  			return EEXIST;
> @@ -231,15 +230,15 @@ dup_table_store(
>  static int
>  collide_dirents(
>  	unsigned long		nr,
> -	const unsigned char	*name,
> +	char			*name,
>  	size_t			namelen,
>  	int			fd)
>  {
>  	struct xfs_name		dname = {
> -		.name		= name,
> +		.name		= (uint8_t *)name,
>  		.len		= namelen,
>  	};
> -	unsigned char		direntname[MAXNAMELEN + 1];
> +	char			direntname[MAXNAMELEN + 1];
>  	struct dup_table	*tab = NULL;
>  	xfs_dahash_t		old_hash;
>  	unsigned long		i;
> @@ -268,10 +267,10 @@ collide_dirents(
>  			return error;
>  	}
>  
> -	dname.name = direntname;
> +	dname.name = (uint8_t *)direntname;
>  	for (i = 0; i < nr; i++) {
>  		strncpy(direntname, name, MAXNAMELEN);
> -		obfuscate_name(old_hash, namelen, direntname, true);
> +		obfuscate_name(old_hash, namelen, (uint8_t *)direntname, true);
>  		ASSERT(old_hash == libxfs_dir2_hashname(mp, &dname));
>  
>  		if (fd >= 0) {
> @@ -297,17 +296,17 @@ collide_dirents(
>  static int
>  collide_xattrs(
>  	unsigned long		nr,
> -	const unsigned char	*name,
> +	char			*name,
>  	size_t			namelen,
>  	int			fd)
>  {
> -	unsigned char		xattrname[MAXNAMELEN + 5];
> +	char			xattrname[MAXNAMELEN + 5];
>  	struct dup_table	*tab = NULL;
>  	xfs_dahash_t		old_hash;
>  	unsigned long		i;
>  	int			error;
>  
> -	old_hash = libxfs_da_hashname(name, namelen);
> +	old_hash = libxfs_da_hashname((uint8_t *)name, namelen);
>  
>  	if (fd >= 0) {
>  		/*
> @@ -330,8 +329,10 @@ collide_xattrs(
>  
>  	for (i = 0; i < nr; i++) {
>  		snprintf(xattrname, MAXNAMELEN + 5, "user.%s", name);
> -		obfuscate_name(old_hash, namelen, xattrname + 5, false);
> -		ASSERT(old_hash == libxfs_da_hashname(xattrname + 5, namelen));
> +		obfuscate_name(old_hash, namelen, (uint8_t *)xattrname + 5,
> +				false);
> +		ASSERT(old_hash == libxfs_da_hashname((uint8_t *)xattrname + 5,
> +				namelen));
>  
>  		if (fd >= 0) {
>  			error = fsetxattr(fd, xattrname, "1", 1, 0);
> -- 
> 2.39.2
> 

  reply	other threads:[~2023-11-03 20:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-03 16:02 [PATCH] db: fix unsigned char related warnings Christoph Hellwig
2023-11-03 20:38 ` Darrick J. Wong [this message]
2023-11-06  6:59   ` Christoph Hellwig
2023-11-06 22:21     ` Darrick J. Wong

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=20231103203813.GG1205143@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=hch@lst.de \
    --cc=linux-xfs@vger.kernel.org \
    /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