mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: Markus Elfring <Markus.Elfring@web.de>,
	anna@kernel.org, brauner@kernel.org, chuck.lever@oracle.com,
	hch@lst.de, trondmy@kernel.org
Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-nfs@vger.kernel.org
Subject: Re: [PATCH] NFS: Use common error handling code in nfs_alloc_server()
Date: Sat, 13 Jun 2026 22:24:35 +0200	[thread overview]
Message-ID: <1c8e10c9-def7-4f0d-8aa1-23c8035a38c8@wanadoo.fr> (raw)
In-Reply-To: <0d2d7158-45c3-4c8b-8ca5-33a5b3445343@web.de>

Le 10/06/2026 à 18:35, Markus Elfring a écrit :
> From: Markus Elfring <elfring-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
> Date: Wed, 10 Jun 2026 18:28:17 +0200
> 
> Use an additional label so that a bit of exception handling can be better
> reused at the end of this function implementation.
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring <elfring-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
> ---
>   fs/nfs/client.c | 16 ++++++++--------
>   1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/nfs/client.c b/fs/nfs/client.c
> index 73b95318ba48..50482257667d 100644
> --- a/fs/nfs/client.c
> +++ b/fs/nfs/client.c
> @@ -1063,10 +1063,8 @@ struct nfs_server *nfs_alloc_server(void)
>   		return NULL;
>   
>   	server->s_sysfs_id = ida_alloc(&s_sysfs_ids, GFP_KERNEL);

If an error occurs after a successful ida_alloc(), then ida_free() needs 
to be called in the error handling path.

CJ

> -	if (server->s_sysfs_id < 0) {
> -		kfree(server);
> -		return NULL;
> -	}
> +	if (server->s_sysfs_id < 0)
> +		goto free_server;
>   
>   	server->client = server->client_acl = ERR_PTR(-EINVAL);
>   
> @@ -1087,10 +1085,8 @@ struct nfs_server *nfs_alloc_server(void)
>   	atomic_long_set(&server->nr_active_delegations, 0);
>   
>   	server->io_stats = nfs_alloc_iostats();
> -	if (!server->io_stats) {
> -		kfree(server);
> -		return NULL;
> -	}
> +	if (!server->io_stats)
> +		goto free_server;
>   
>   	server->change_attr_type = NFS4_CHANGE_TYPE_IS_UNDEFINED;
>   
> @@ -1103,6 +1099,10 @@ struct nfs_server *nfs_alloc_server(void)
>   	rpc_init_wait_queue(&server->uoc_rpcwaitq, "NFS UOC");
>   
>   	return server;
> +
> +free_server:
> +	kfree(server);
> +	return NULL;
>   }
>   EXPORT_SYMBOL_GPL(nfs_alloc_server);
>   


  reply	other threads:[~2026-06-13 20:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-10 16:35 Markus Elfring
2026-06-13 20:24 ` Christophe JAILLET [this message]
2026-06-14  8:37   ` [PATCH v2 0/2] NFS: Fix exception handling " Markus Elfring
2026-06-14  8:42     ` [PATCH v2 1/2] NFS: Prevent resource leak " Markus Elfring
2026-06-14  8:43     ` [PATCH v2 2/2] NFS: Use common error handling code " Markus Elfring

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=1c8e10c9-def7-4f0d-8aa1-23c8035a38c8@wanadoo.fr \
    --to=christophe.jaillet@wanadoo.fr \
    --cc=Markus.Elfring@web.de \
    --cc=anna@kernel.org \
    --cc=brauner@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=hch@lst.de \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=trondmy@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

all inboxes | Powered by JetHome®