All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Marzinski <bmarzins@redhat.com>
To: Martin Wilck <martin.wilck@suse.com>
Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>,
	Xose Vazquez Perez <xose.vazquez@gmail.com>,
	Martin Wilck <mwilck@suse.com>,
	dm-devel@lists.linux.dev
Subject: Re: [PATCH v2 8/8] libmpathutil: remove VECTOR_DEFAULT_SIZE macro
Date: Mon, 12 May 2025 14:44:48 -0400	[thread overview]
Message-ID: <aCJBoKZjE3ZbPuwO@redhat.com> (raw)
In-Reply-To: <20250507190552.209637-9-mwilck@suse.com>

On Wed, May 07, 2025 at 09:05:52PM +0200, Martin Wilck wrote:
> We always add or remove a single element in vector_add_slot() and
> vector_remove_slot(). Use of the VECTOR_DEFAULT_SIZE macro suggests that
> its value can be changed, but this is not the case.
> 
> Remove the macro.
> 
> Signed-off-by: Martin Wilck <mwilck@suse.com>

Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>

> ---
>  libmpathutil/vector.c | 4 ++--
>  libmpathutil/vector.h | 3 +--
>  2 files changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/libmpathutil/vector.c b/libmpathutil/vector.c
> index 6ad5dd5..34a8512 100644
> --- a/libmpathutil/vector.c
> +++ b/libmpathutil/vector.c
> @@ -45,7 +45,7 @@ vector_alloc_slot(vector v)
>  	if (!v)
>  		return false;
>  
> -	new_allocated = v->allocated + VECTOR_DEFAULT_SIZE;
> +	new_allocated = v->allocated + 1;
>  	new_slot = realloc(v->slot, sizeof (void *) * new_allocated);
>  	if (!new_slot)
>  		return false;
> @@ -115,7 +115,7 @@ vector_del_slot(vector v, int slot)
>  	for (i = slot + 1; i < VECTOR_SIZE(v); i++)
>  		v->slot[i - 1] = v->slot[i];
>  
> -	v->allocated -= VECTOR_DEFAULT_SIZE;
> +	v->allocated--;
>  
>  	if (v->allocated <= 0) {
>  		free(v->slot);
> diff --git a/libmpathutil/vector.h b/libmpathutil/vector.h
> index 171ab6a..0a5b32e 100644
> --- a/libmpathutil/vector.h
> +++ b/libmpathutil/vector.h
> @@ -32,8 +32,7 @@ struct vector_s {
>  };
>  typedef struct vector_s *vector;
>  
> -#define VECTOR_DEFAULT_SIZE 1
> -#define VECTOR_SIZE(V)   ((V) ? ((V)->allocated) / VECTOR_DEFAULT_SIZE : 0)
> +#define VECTOR_SIZE(V)   ((V) ? (V)->allocated : 0)
>  #define VECTOR_SLOT(V,E) (((V) && (E) < VECTOR_SIZE(V) && (E) >= 0) ? (V)->slot[(E)] : NULL)
>  #define VECTOR_LAST_SLOT(V)   (((V) && VECTOR_SIZE(V) > 0) ? (V)->slot[(VECTOR_SIZE(V) - 1)] : NULL)
>  
> -- 
> 2.49.0


      reply	other threads:[~2025-05-12 18:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-07 19:05 [PATCH v2 0/8] multipath-tools: static analyzer fixes Martin Wilck
2025-05-07 19:05 ` [PATCH v2 1/8] kpartx_id: fix shellcheck reported errors Martin Wilck
2025-05-07 19:05 ` [PATCH v2 2/8] kpartx: fix file descriptor leak Martin Wilck
2025-05-07 19:05 ` [PATCH v2 3/8] libmpathpersist: fix memory leak in mpath_prout_rel() Martin Wilck
2025-05-07 19:05 ` [PATCH v2 4/8] libmpathutil: vector_del_slot: modify v->allocated if realloc fails Martin Wilck
2025-05-12 18:34   ` Benjamin Marzinski
2025-05-07 19:05 ` [PATCH v2 5/8] libmultipath: fix undefined behavior in 31-bit shift Martin Wilck
2025-05-07 19:05 ` [PATCH v2 6/8] libmultipath: prioritizers/iet: fix possible NULL dereference Martin Wilck
2025-05-07 19:05 ` [PATCH v2 7/8] libmpathutil: remove vector_repack() Martin Wilck
2025-05-12 18:35   ` Benjamin Marzinski
2025-05-07 19:05 ` [PATCH v2 8/8] libmpathutil: remove VECTOR_DEFAULT_SIZE macro Martin Wilck
2025-05-12 18:44   ` Benjamin Marzinski [this message]

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=aCJBoKZjE3ZbPuwO@redhat.com \
    --to=bmarzins@redhat.com \
    --cc=christophe.varoqui@opensvc.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=martin.wilck@suse.com \
    --cc=mwilck@suse.com \
    --cc=xose.vazquez@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.