public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ceph: improve error handling in ceph_mdsmap_decode
@ 2013-05-28 14:59 Emil Goode
  2013-05-28 15:54 ` Sage Weil
  2013-05-29  6:22 ` [patch] ceph: tidy ceph_mdsmap_decode() a little Dan Carpenter
  0 siblings, 2 replies; 6+ messages in thread
From: Emil Goode @ 2013-05-28 14:59 UTC (permalink / raw)
  To: sage; +Cc: ceph-devel, linux-kernel, kernel-janitors, Emil Goode

This patch makes the following improvements to the error handling
in the ceph_mdsmap_decode function:

- Add a NULL check for return value from kcalloc
- Make use of the variable err

Signed-off-by: Emil Goode <emilgoode@gmail.com>
---
 fs/ceph/mdsmap.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/ceph/mdsmap.c b/fs/ceph/mdsmap.c
index 9278dec..d4d3897 100644
--- a/fs/ceph/mdsmap.c
+++ b/fs/ceph/mdsmap.c
@@ -138,6 +138,8 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
 				m->m_info[mds].export_targets =
 					kcalloc(num_export_targets, sizeof(u32),
 						GFP_NOFS);
+				if (m->m_info[mds].export_targets == NULL)
+					goto badmem;
 				for (j = 0; j < num_export_targets; j++)
 					m->m_info[mds].export_targets[j] =
 					       ceph_decode_32(&pexport_targets);
@@ -170,7 +172,7 @@ bad:
 		       DUMP_PREFIX_OFFSET, 16, 1,
 		       start, end - start, true);
 	ceph_mdsmap_destroy(m);
-	return ERR_PTR(-EINVAL);
+	return ERR_PTR(err);
 }
 
 void ceph_mdsmap_destroy(struct ceph_mdsmap *m)
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] ceph: improve error handling in ceph_mdsmap_decode
  2013-05-28 14:59 [PATCH] ceph: improve error handling in ceph_mdsmap_decode Emil Goode
@ 2013-05-28 15:54 ` Sage Weil
  2013-05-29  6:22 ` [patch] ceph: tidy ceph_mdsmap_decode() a little Dan Carpenter
  1 sibling, 0 replies; 6+ messages in thread
From: Sage Weil @ 2013-05-28 15:54 UTC (permalink / raw)
  To: Emil Goode; +Cc: ceph-devel, linux-kernel, kernel-janitors

Applied to ceph tree; thanks!

On Tue, 28 May 2013, Emil Goode wrote:

> This patch makes the following improvements to the error handling
> in the ceph_mdsmap_decode function:
> 
> - Add a NULL check for return value from kcalloc
> - Make use of the variable err
> 
> Signed-off-by: Emil Goode <emilgoode@gmail.com>
> ---
>  fs/ceph/mdsmap.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/ceph/mdsmap.c b/fs/ceph/mdsmap.c
> index 9278dec..d4d3897 100644
> --- a/fs/ceph/mdsmap.c
> +++ b/fs/ceph/mdsmap.c
> @@ -138,6 +138,8 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
>  				m->m_info[mds].export_targets =
>  					kcalloc(num_export_targets, sizeof(u32),
>  						GFP_NOFS);
> +				if (m->m_info[mds].export_targets == NULL)
> +					goto badmem;
>  				for (j = 0; j < num_export_targets; j++)
>  					m->m_info[mds].export_targets[j] =
>  					       ceph_decode_32(&pexport_targets);
> @@ -170,7 +172,7 @@ bad:
>  		       DUMP_PREFIX_OFFSET, 16, 1,
>  		       start, end - start, true);
>  	ceph_mdsmap_destroy(m);
> -	return ERR_PTR(-EINVAL);
> +	return ERR_PTR(err);
>  }
>  
>  void ceph_mdsmap_destroy(struct ceph_mdsmap *m)
> -- 
> 1.7.10.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [patch] ceph: tidy ceph_mdsmap_decode() a little
  2013-05-28 14:59 [PATCH] ceph: improve error handling in ceph_mdsmap_decode Emil Goode
  2013-05-28 15:54 ` Sage Weil
@ 2013-05-29  6:22 ` Dan Carpenter
  2013-05-29  7:17   ` walter harms
  2013-05-29 11:45   ` Alex Elder
  1 sibling, 2 replies; 6+ messages in thread
From: Dan Carpenter @ 2013-05-29  6:22 UTC (permalink / raw)
  To: Sage Weil; +Cc: ceph-devel, linux-kernel, kernel-janitors, Emil Goode

I introduced a new temporary variable "info" instead of
"m->m_info[mds]".  Also I reversed the if condition and pulled
everything in one indent level.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
This goes on top of Emil Goode's patch.

diff --git a/fs/ceph/mdsmap.c b/fs/ceph/mdsmap.c
index d4d3897..132b64e 100644
--- a/fs/ceph/mdsmap.c
+++ b/fs/ceph/mdsmap.c
@@ -92,6 +92,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
 		u32 num_export_targets;
 		void *pexport_targets = NULL;
 		struct ceph_timespec laggy_since;
+		struct ceph_mds_info *info;
 
 		ceph_decode_need(p, end, sizeof(u64)*2 + 1 + sizeof(u32), bad);
 		global_id = ceph_decode_64(p);
@@ -126,26 +127,27 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
 		     i+1, n, global_id, mds, inc,
 		     ceph_pr_addr(&addr.in_addr),
 		     ceph_mds_state_name(state));
-		if (mds >= 0 && mds < m->m_max_mds && state > 0) {
-			m->m_info[mds].global_id = global_id;
-			m->m_info[mds].state = state;
-			m->m_info[mds].addr = addr;
-			m->m_info[mds].laggy =
-				(laggy_since.tv_sec != 0 ||
-				 laggy_since.tv_nsec != 0);
-			m->m_info[mds].num_export_targets = num_export_targets;
-			if (num_export_targets) {
-				m->m_info[mds].export_targets =
-					kcalloc(num_export_targets, sizeof(u32),
-						GFP_NOFS);
-				if (m->m_info[mds].export_targets == NULL)
-					goto badmem;
-				for (j = 0; j < num_export_targets; j++)
-					m->m_info[mds].export_targets[j] =
-					       ceph_decode_32(&pexport_targets);
-			} else {
-				m->m_info[mds].export_targets = NULL;
-			}
+
+		if (mds < 0 || mds >= m->m_max_mds || state <= 0)
+			continue;
+
+		info = &m->m_info[mds];
+		info->global_id = global_id;
+		info->state = state;
+		info->addr = addr;
+		info->laggy = (laggy_since.tv_sec != 0 ||
+			       laggy_since.tv_nsec != 0);
+		info->num_export_targets = num_export_targets;
+		if (num_export_targets) {
+			info->export_targets = kcalloc(num_export_targets,
+						       sizeof(u32), GFP_NOFS);
+			if (info->export_targets == NULL)
+				goto badmem;
+			for (j = 0; j < num_export_targets; j++)
+				info->export_targets[j] =
+				       ceph_decode_32(&pexport_targets);
+		} else {
+			info->export_targets = NULL;
 		}
 	}
 

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [patch] ceph: tidy ceph_mdsmap_decode() a little
  2013-05-29  6:22 ` [patch] ceph: tidy ceph_mdsmap_decode() a little Dan Carpenter
@ 2013-05-29  7:17   ` walter harms
  2013-05-29  7:55     ` Dan Carpenter
  2013-05-29 11:45   ` Alex Elder
  1 sibling, 1 reply; 6+ messages in thread
From: walter harms @ 2013-05-29  7:17 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Sage Weil, ceph-devel, linux-kernel, kernel-janitors, Emil Goode



Am 29.05.2013 08:22, schrieb Dan Carpenter:
> I introduced a new temporary variable "info" instead of
> "m->m_info[mds]".  Also I reversed the if condition and pulled
> everything in one indent level.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> This goes on top of Emil Goode's patch.
> 
> diff --git a/fs/ceph/mdsmap.c b/fs/ceph/mdsmap.c
> index d4d3897..132b64e 100644
> --- a/fs/ceph/mdsmap.c
> +++ b/fs/ceph/mdsmap.c
> @@ -92,6 +92,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
>  		u32 num_export_targets;
>  		void *pexport_targets = NULL;
>  		struct ceph_timespec laggy_since;
> +		struct ceph_mds_info *info;
>  
>  		ceph_decode_need(p, end, sizeof(u64)*2 + 1 + sizeof(u32), bad);
>  		global_id = ceph_decode_64(p);
> @@ -126,26 +127,27 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
>  		     i+1, n, global_id, mds, inc,
>  		     ceph_pr_addr(&addr.in_addr),
>  		     ceph_mds_state_name(state));
> -		if (mds >= 0 && mds < m->m_max_mds && state > 0) {
> -			m->m_info[mds].global_id = global_id;
> -			m->m_info[mds].state = state;
> -			m->m_info[mds].addr = addr;
> -			m->m_info[mds].laggy =
> -				(laggy_since.tv_sec != 0 ||
> -				 laggy_since.tv_nsec != 0);
> -			m->m_info[mds].num_export_targets = num_export_targets;
> -			if (num_export_targets) {
> -				m->m_info[mds].export_targets =
> -					kcalloc(num_export_targets, sizeof(u32),
> -						GFP_NOFS);
> -				if (m->m_info[mds].export_targets == NULL)
> -					goto badmem;
> -				for (j = 0; j < num_export_targets; j++)
> -					m->m_info[mds].export_targets[j] =
> -					       ceph_decode_32(&pexport_targets);
> -			} else {
> -				m->m_info[mds].export_targets = NULL;
> -			}
> +
> +		if (mds < 0 || mds >= m->m_max_mds || state <= 0)
> +			continue;
> +
> +		info = &m->m_info[mds];
> +		info->global_id = global_id;
> +		info->state = state;
> +		info->addr = addr;
> +		info->laggy = (laggy_since.tv_sec != 0 ||
> +			       laggy_since.tv_nsec != 0);
> +		info->num_export_targets = num_export_targets;
personally i would go for:
		info->export_targets = NULL;
and remove the else below.

hope that helps,

re,
 wh

> +		if (num_export_targets) {
> +			info->export_targets = kcalloc(num_export_targets,
> +						       sizeof(u32), GFP_NOFS);
> +			if (info->export_targets == NULL)
> +				goto badmem;
> +			for (j = 0; j < num_export_targets; j++)
> +				info->export_targets[j] =
> +				       ceph_decode_32(&pexport_targets);
> +		} else {
> +			info->export_targets = NULL;
>  		}
>  	}
>  
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch] ceph: tidy ceph_mdsmap_decode() a little
  2013-05-29  7:17   ` walter harms
@ 2013-05-29  7:55     ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2013-05-29  7:55 UTC (permalink / raw)
  To: walter harms
  Cc: Sage Weil, ceph-devel, linux-kernel, kernel-janitors, Emil Goode

On Wed, May 29, 2013 at 09:17:21AM +0200, walter harms wrote:
> personally i would go for:
> 		info->export_targets = NULL;
> and remove the else below.
> 

I don't have strong feelings one way or the other, but honestly, I
think the way I sent it is more clear.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch] ceph: tidy ceph_mdsmap_decode() a little
  2013-05-29  6:22 ` [patch] ceph: tidy ceph_mdsmap_decode() a little Dan Carpenter
  2013-05-29  7:17   ` walter harms
@ 2013-05-29 11:45   ` Alex Elder
  1 sibling, 0 replies; 6+ messages in thread
From: Alex Elder @ 2013-05-29 11:45 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Sage Weil, ceph-devel, linux-kernel, kernel-janitors, Emil Goode

On 05/29/2013 01:22 AM, Dan Carpenter wrote:
> I introduced a new temporary variable "info" instead of
> "m->m_info[mds]".  Also I reversed the if condition and pulled
> everything in one indent level.

Looks good.  I will apply this for you.

Reviewed-by: Alex Elder <elder@inktank.com>

> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> This goes on top of Emil Goode's patch.
> 
> diff --git a/fs/ceph/mdsmap.c b/fs/ceph/mdsmap.c
> index d4d3897..132b64e 100644
> --- a/fs/ceph/mdsmap.c
> +++ b/fs/ceph/mdsmap.c
> @@ -92,6 +92,7 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
>  		u32 num_export_targets;
>  		void *pexport_targets = NULL;
>  		struct ceph_timespec laggy_since;
> +		struct ceph_mds_info *info;
>  
>  		ceph_decode_need(p, end, sizeof(u64)*2 + 1 + sizeof(u32), bad);
>  		global_id = ceph_decode_64(p);

. . .


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-05-29 11:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-28 14:59 [PATCH] ceph: improve error handling in ceph_mdsmap_decode Emil Goode
2013-05-28 15:54 ` Sage Weil
2013-05-29  6:22 ` [patch] ceph: tidy ceph_mdsmap_decode() a little Dan Carpenter
2013-05-29  7:17   ` walter harms
2013-05-29  7:55     ` Dan Carpenter
2013-05-29 11:45   ` Alex Elder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox