All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: lustre-devel@lists.lustre.org
Subject: [lustre-devel] [PATCH] staging:lustre: Prevent duplicate CT registrations
Date: Mon, 26 Oct 2015 11:52:49 +0300	[thread overview]
Message-ID: <20151026085249.GW7340@mwanda> (raw)
In-Reply-To: <1445630357-27149-3-git-send-email-jsimmons@infradead.org>

On Fri, Oct 23, 2015 at 03:59:14PM -0400, James Simmons wrote:
> diff --git a/drivers/staging/lustre/lustre/lmv/lmv_obd.c b/drivers/staging/lustre/lustre/lmv/lmv_obd.c
> index 635a93c..d6d70d8 100644
> --- a/drivers/staging/lustre/lustre/lmv/lmv_obd.c
> +++ b/drivers/staging/lustre/lustre/lmv/lmv_obd.c
> @@ -794,7 +794,9 @@ static void lmv_hsm_req_build(struct lmv_obd *lmv,
>  static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len,
>  				 struct lustre_kernelcomm *lk, void *uarg)
>  {
> -	int	i, rc = 0;
> +	struct kkuc_ct_data *kcd = NULL;
> +	int rc = 0;
> +	__u32 i;

We have been introducing a lot of new __u32 types here and I just
assumed there was a reason for it but this one is clearly wrong.  The
new code implies that ->ld_tgt_count can overflow INT_MAX which is not
true and that this is code shared with userspace which might be true but
it's not described in the changelog.  Is this a static checker fix?
Stop using that broken static checker, because the correct type here is
int.

Anyway, stop making gratuitous unrelated changes (like the white space
changes to local declarations).  I feel like I have held off commenting
on this for a while and shown great restraint.  :P

> -	rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group);
> +	rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group, (void**)&kcd);
> +	if (kcd != NULL)
> +		kfree(kcd);

NULL check not needed.

> +
>  	return rc;
>  }
>  
>  static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
>  			       struct lustre_kernelcomm *lk, void *uarg)
>  {
> -	struct file	*filp;
> -	int		 i, j, err;
> -	int		 rc = 0;
> -	bool		 any_set = false;
> +	struct file *filp;
> +	__u32 i, j;
> +	int err, rc = 0;
> +	bool any_set = false;
> +	struct kkuc_ct_data *kcd;
>  
>  	/* All or nothing: try to register to all MDS.
>  	 * In case of failure, unregister from previous MDS,
> @@ -854,12 +860,25 @@ static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
>  
>  	/* at least one registration done, with no failure */
>  	filp = fget(lk->lk_wfd);
> -	if (filp == NULL) {
> +	if (filp == NULL)
>  		return -EBADF;
> -	}
> -	rc = libcfs_kkuc_group_add(filp, lk->lk_uid, lk->lk_group, lk->lk_data);
> -	if (rc != 0 && filp != NULL)
> +
> +	kcd = kzalloc(sizeof(*kcd), GFP_NOFS);
> +	if (kcd == NULL) {
>  		fput(filp);
> +		return -ENOMEM;
> +	}
> +	kcd->kcd_magic = KKUC_CT_DATA_MAGIC;
> +	kcd->kcd_uuid = lmv->cluuid;
> +	kcd->kcd_archive = lk->lk_data;
> +
> +	rc = libcfs_kkuc_group_add(filp, lk->lk_uid, lk->lk_group, kcd);
> +	if (rc != 0) {

These double negatives are a pet peev of mine.  "if (rc) {"  Comparing
with zero like this is idiomatic when you're talking about the number
zero or strcmp().  Can we use a goto for unwinding?  goto free_kcd;

> +		if (filp != NULL)

The earlier NULL check means this can't happen.

> +			fput(filp);
> +		kfree(kcd);
> +	}
> +
>  	return rc;

	return 0;

free_kcd:
	kfree(kcd);
put_filp:
	fput(filp);

	return rc;

regards,
dan carpenter

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: James Simmons <jsimmons@infradead.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	devel@driverdev.osuosl.org, Oleg Drokin <oleg.drokin@intel.com>,
	Andreas Dilger <andreas.dilger@intel.com>,
	Henri Doreau <henri.doreau@cea.fr>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	lustre-devel@lists.lustre.org
Subject: Re: [PATCH] staging:lustre: Prevent duplicate CT registrations
Date: Mon, 26 Oct 2015 11:52:49 +0300	[thread overview]
Message-ID: <20151026085249.GW7340@mwanda> (raw)
In-Reply-To: <1445630357-27149-3-git-send-email-jsimmons@infradead.org>

On Fri, Oct 23, 2015 at 03:59:14PM -0400, James Simmons wrote:
> diff --git a/drivers/staging/lustre/lustre/lmv/lmv_obd.c b/drivers/staging/lustre/lustre/lmv/lmv_obd.c
> index 635a93c..d6d70d8 100644
> --- a/drivers/staging/lustre/lustre/lmv/lmv_obd.c
> +++ b/drivers/staging/lustre/lustre/lmv/lmv_obd.c
> @@ -794,7 +794,9 @@ static void lmv_hsm_req_build(struct lmv_obd *lmv,
>  static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len,
>  				 struct lustre_kernelcomm *lk, void *uarg)
>  {
> -	int	i, rc = 0;
> +	struct kkuc_ct_data *kcd = NULL;
> +	int rc = 0;
> +	__u32 i;

We have been introducing a lot of new __u32 types here and I just
assumed there was a reason for it but this one is clearly wrong.  The
new code implies that ->ld_tgt_count can overflow INT_MAX which is not
true and that this is code shared with userspace which might be true but
it's not described in the changelog.  Is this a static checker fix?
Stop using that broken static checker, because the correct type here is
int.

Anyway, stop making gratuitous unrelated changes (like the white space
changes to local declarations).  I feel like I have held off commenting
on this for a while and shown great restraint.  :P

> -	rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group);
> +	rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group, (void**)&kcd);
> +	if (kcd != NULL)
> +		kfree(kcd);

NULL check not needed.

> +
>  	return rc;
>  }
>  
>  static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
>  			       struct lustre_kernelcomm *lk, void *uarg)
>  {
> -	struct file	*filp;
> -	int		 i, j, err;
> -	int		 rc = 0;
> -	bool		 any_set = false;
> +	struct file *filp;
> +	__u32 i, j;
> +	int err, rc = 0;
> +	bool any_set = false;
> +	struct kkuc_ct_data *kcd;
>  
>  	/* All or nothing: try to register to all MDS.
>  	 * In case of failure, unregister from previous MDS,
> @@ -854,12 +860,25 @@ static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
>  
>  	/* at least one registration done, with no failure */
>  	filp = fget(lk->lk_wfd);
> -	if (filp == NULL) {
> +	if (filp == NULL)
>  		return -EBADF;
> -	}
> -	rc = libcfs_kkuc_group_add(filp, lk->lk_uid, lk->lk_group, lk->lk_data);
> -	if (rc != 0 && filp != NULL)
> +
> +	kcd = kzalloc(sizeof(*kcd), GFP_NOFS);
> +	if (kcd == NULL) {
>  		fput(filp);
> +		return -ENOMEM;
> +	}
> +	kcd->kcd_magic = KKUC_CT_DATA_MAGIC;
> +	kcd->kcd_uuid = lmv->cluuid;
> +	kcd->kcd_archive = lk->lk_data;
> +
> +	rc = libcfs_kkuc_group_add(filp, lk->lk_uid, lk->lk_group, kcd);
> +	if (rc != 0) {

These double negatives are a pet peev of mine.  "if (rc) {"  Comparing
with zero like this is idiomatic when you're talking about the number
zero or strcmp().  Can we use a goto for unwinding?  goto free_kcd;

> +		if (filp != NULL)

The earlier NULL check means this can't happen.

> +			fput(filp);
> +		kfree(kcd);
> +	}
> +
>  	return rc;

	return 0;

free_kcd:
	kfree(kcd);
put_filp:
	fput(filp);

	return rc;

regards,
dan carpenter


  reply	other threads:[~2015-10-26  8:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-23 19:59 [lustre-devel] [PATCH 0/5] staging:lustre: split kernel comm between user and kernel James Simmons
2015-10-23 19:59 ` James Simmons
2015-10-23 19:59 ` [lustre-devel] [PATCH 1/5] staging:lustre: kg_sem semaphore handling is incorrectly James Simmons
2015-10-23 19:59   ` James Simmons
2015-10-23 19:59 ` [lustre-devel] [PATCH] staging:lustre: Prevent duplicate CT registrations James Simmons
2015-10-23 19:59   ` James Simmons
2015-10-26  8:52   ` Dan Carpenter [this message]
2015-10-26  8:52     ` Dan Carpenter
2015-11-04  0:20     ` [lustre-devel] " Simmons, James A.
2015-11-04  0:20       ` Simmons, James A.
2015-10-23 19:59 ` [lustre-devel] [PATCH] staging:lustre: move kernel_user_comm.c from libcfs to lustre James Simmons
2015-10-23 19:59   ` James Simmons
2015-10-23 19:59 ` [lustre-devel] [PATCH 4/5] staging:lustre: split kernel comm between user and kernel James Simmons
2015-10-23 19:59   ` James Simmons
2015-10-23 19:59 ` [lustre-devel] [PATCH 5/5] staging:lustre: Update license and copyright for kernel comm James Simmons
2015-10-23 19:59   ` James Simmons
2015-10-25  1:56 ` [lustre-devel] [PATCH 0/5] staging:lustre: split kernel comm between user and kernel Greg Kroah-Hartman
2015-10-25  1:56   ` Greg Kroah-Hartman

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=20151026085249.GW7340@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=lustre-devel@lists.lustre.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 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.