public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] lustre/mdc_lib: fix possible null pointer dereference
@ 2014-03-05 13:04 Maxin B. John
  2014-03-05 13:04 ` [PATCH 2/2] lustre/lov_obd: " Maxin B. John
  2014-03-05 18:53 ` [PATCH 1/2] lustre/mdc_lib: " Dan Carpenter
  0 siblings, 2 replies; 6+ messages in thread
From: Maxin B. John @ 2014-03-05 13:04 UTC (permalink / raw)
  To: linux-kernel, devel
  Cc: gregkh, andreas.dilger, josh, bergwolf, dulshani.gunawardhana89,
	jinshan.xiong, alexey.zhuravlev, Maxin B. John

From: "Maxin B. John" <maxin.john@enea.com>

cppcheck reported possible null pointer dereference in mdc_lib.c

[lustre/lustre/mdc/mdc_lib.c:233]: (error) Possible null pointer dereference
: op_data - otherwise it is redundant to check if op_data is null at line 226

Signed-off-by: Maxin B. John <maxin.john@enea.com>
---
 drivers/staging/lustre/lustre/mdc/mdc_lib.c |   41 ++++++++++++++-------------
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/lustre/lustre/mdc/mdc_lib.c b/drivers/staging/lustre/lustre/mdc/mdc_lib.c
index 91f6876..594e07c 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_lib.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_lib.c
@@ -223,29 +223,30 @@ void mdc_open_pack(struct ptlrpc_request *req, struct md_op_data *op_data,
 	rec->cr_fsuid    = from_kuid(&init_user_ns, current_fsuid());
 	rec->cr_fsgid    = from_kgid(&init_user_ns, current_fsgid());
 	rec->cr_cap      = cfs_curproc_cap_pack();
+
 	if (op_data != NULL) {
 		rec->cr_fid1 = op_data->op_fid1;
 		rec->cr_fid2 = op_data->op_fid2;
-	}
-	rec->cr_mode     = mode;
-	cr_flags = mds_pack_open_flags(flags, mode);
-	rec->cr_rdev     = rdev;
-	rec->cr_time     = op_data->op_mod_time;
-	rec->cr_suppgid1 = op_data->op_suppgids[0];
-	rec->cr_suppgid2 = op_data->op_suppgids[1];
-	rec->cr_bias     = op_data->op_bias;
-	rec->cr_umask    = current_umask();
-	rec->cr_old_handle = op_data->op_handle;
-
-	mdc_pack_capa(req, &RMF_CAPA1, op_data->op_capa1);
-	/* the next buffer is child capa, which is used for replay,
-	 * will be packed from the data in reply message. */
-
-	if (op_data->op_name) {
-		tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
-		LOGL0(op_data->op_name, op_data->op_namelen, tmp);
-		if (op_data->op_bias & MDS_CREATE_VOLATILE)
-			cr_flags |= MDS_OPEN_VOLATILE;
+		rec->cr_mode     = mode;
+		cr_flags = mds_pack_open_flags(flags, mode);
+		rec->cr_rdev     = rdev;
+		rec->cr_time     = op_data->op_mod_time;
+		rec->cr_suppgid1 = op_data->op_suppgids[0];
+		rec->cr_suppgid2 = op_data->op_suppgids[1];
+		rec->cr_bias     = op_data->op_bias;
+		rec->cr_umask    = current_umask();
+		rec->cr_old_handle = op_data->op_handle;
+
+		mdc_pack_capa(req, &RMF_CAPA1, op_data->op_capa1);
+		/* the next buffer is child capa, which is used for replay,
+		* will be packed from the data in reply message. */
+
+		if (op_data->op_name) {
+			tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
+			LOGL0(op_data->op_name, op_data->op_namelen, tmp);
+			if (op_data->op_bias & MDS_CREATE_VOLATILE)
+				cr_flags |= MDS_OPEN_VOLATILE;
+		}
 	}
 
 	if (lmm) {
-- 
1.7.10.4


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

* [PATCH 2/2] lustre/lov_obd: fix possible null pointer dereference
  2014-03-05 13:04 [PATCH 1/2] lustre/mdc_lib: fix possible null pointer dereference Maxin B. John
@ 2014-03-05 13:04 ` Maxin B. John
  2014-03-06 19:53   ` Greg KH
  2014-03-05 18:53 ` [PATCH 1/2] lustre/mdc_lib: " Dan Carpenter
  1 sibling, 1 reply; 6+ messages in thread
From: Maxin B. John @ 2014-03-05 13:04 UTC (permalink / raw)
  To: linux-kernel, devel
  Cc: gregkh, andreas.dilger, josh, bergwolf, dulshani.gunawardhana89,
	jinshan.xiong, alexey.zhuravlev, Maxin B. John

From: "Maxin B. John" <maxin.john@enea.com>

osc_obd can be NULL. cppcheck reported this:
[lustre/lustre/lov/lov_obd.c:283]: (error) Possible null pointer dereference:
osc_obd - otherwise it is redundant to check if osc_obd is null at line 295

Signed-off-by: Maxin B. John <maxin.john@enea.com>
---
 drivers/staging/lustre/lustre/lov/lov_obd.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/lustre/lustre/lov/lov_obd.c b/drivers/staging/lustre/lustre/lov/lov_obd.c
index 50a77c5..5c0271c 100644
--- a/drivers/staging/lustre/lustre/lov/lov_obd.c
+++ b/drivers/staging/lustre/lustre/lov/lov_obd.c
@@ -279,8 +279,6 @@ static int lov_disconnect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
 	int rc;
 
 	osc_obd = class_exp2obd(tgt->ltd_exp);
-	CDEBUG(D_CONFIG, "%s: disconnecting target %s\n",
-	       obd->obd_name, osc_obd->obd_name);
 
 	if (tgt->ltd_active) {
 		tgt->ltd_active = 0;
@@ -289,14 +287,17 @@ static int lov_disconnect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
 	}
 
 	lov_proc_dir = obd->obd_proc_private;
-	if (lov_proc_dir)
-		lprocfs_remove_proc_entry(osc_obd->obd_name, lov_proc_dir);
 
 	if (osc_obd) {
 		/* Pass it on to our clients.
 		 * XXX This should be an argument to disconnect,
 		 * XXX not a back-door flag on the OBD.  Ah well.
 		 */
+		CDEBUG(D_CONFIG, "%s: disconnecting target %s\n",
+			obd->obd_name, osc_obd->obd_name);
+		if (lov_proc_dir)
+			lprocfs_remove_proc_entry(osc_obd->obd_name,
+							lov_proc_dir);
 		osc_obd->obd_force = obd->obd_force;
 		osc_obd->obd_fail = obd->obd_fail;
 		osc_obd->obd_no_recov = obd->obd_no_recov;
-- 
1.7.10.4


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

* Re: [PATCH 1/2] lustre/mdc_lib: fix possible null pointer dereference
  2014-03-05 13:04 [PATCH 1/2] lustre/mdc_lib: fix possible null pointer dereference Maxin B. John
  2014-03-05 13:04 ` [PATCH 2/2] lustre/lov_obd: " Maxin B. John
@ 2014-03-05 18:53 ` Dan Carpenter
  2014-03-06 19:51   ` Greg KH
  1 sibling, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2014-03-05 18:53 UTC (permalink / raw)
  To: Maxin B. John
  Cc: linux-kernel, devel, andreas.dilger, gregkh, bergwolf,
	alexey.zhuravlev, josh, dulshani.gunawardhana89, jinshan.xiong,
	Maxin B. John

On Wed, Mar 05, 2014 at 02:04:35PM +0100, Maxin B. John wrote:
> From: "Maxin B. John" <maxin.john@enea.com>
> 
> cppcheck reported possible null pointer dereference in mdc_lib.c
> 
> [lustre/lustre/mdc/mdc_lib.c:233]: (error) Possible null pointer dereference
> : op_data - otherwise it is redundant to check if op_data is null at line 226
> 

There is only one caller and "op_data" is not NULL.

regards,
dan carpenter


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

* Re: [PATCH 1/2] lustre/mdc_lib: fix possible null pointer dereference
  2014-03-05 18:53 ` [PATCH 1/2] lustre/mdc_lib: " Dan Carpenter
@ 2014-03-06 19:51   ` Greg KH
  2014-03-06 21:41     ` Maxin B. John
  0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2014-03-06 19:51 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Maxin B. John, devel, andreas.dilger, bergwolf, alexey.zhuravlev,
	linux-kernel, dulshani.gunawardhana89, josh, jinshan.xiong,
	Maxin B. John

On Wed, Mar 05, 2014 at 09:53:06PM +0300, Dan Carpenter wrote:
> On Wed, Mar 05, 2014 at 02:04:35PM +0100, Maxin B. John wrote:
> > From: "Maxin B. John" <maxin.john@enea.com>
> > 
> > cppcheck reported possible null pointer dereference in mdc_lib.c
> > 
> > [lustre/lustre/mdc/mdc_lib.c:233]: (error) Possible null pointer dereference
> > : op_data - otherwise it is redundant to check if op_data is null at line 226
> > 
> 
> There is only one caller and "op_data" is not NULL.

I agree, John, please fix your tools.  Or check the result and fix the
code so that there isn't false-positives (by not checking for NULL at
all here...)

thanks,

greg k-h

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

* Re: [PATCH 2/2] lustre/lov_obd: fix possible null pointer dereference
  2014-03-05 13:04 ` [PATCH 2/2] lustre/lov_obd: " Maxin B. John
@ 2014-03-06 19:53   ` Greg KH
  0 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2014-03-06 19:53 UTC (permalink / raw)
  To: Maxin B. John
  Cc: linux-kernel, devel, andreas.dilger, bergwolf, alexey.zhuravlev,
	josh, dulshani.gunawardhana89, jinshan.xiong, Maxin B. John

On Wed, Mar 05, 2014 at 02:04:36PM +0100, Maxin B. John wrote:
> From: "Maxin B. John" <maxin.john@enea.com>
> 
> osc_obd can be NULL. cppcheck reported this:
> [lustre/lustre/lov/lov_obd.c:283]: (error) Possible null pointer dereference:
> osc_obd - otherwise it is redundant to check if osc_obd is null at line 295

Same problem, osc_obd can never be NULL, please be more careful with
your patches, and just remove pointless tests instead of papering over
them with patches like this.

thanks.

greg k-h

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

* Re: [PATCH 1/2] lustre/mdc_lib: fix possible null pointer dereference
  2014-03-06 19:51   ` Greg KH
@ 2014-03-06 21:41     ` Maxin B. John
  0 siblings, 0 replies; 6+ messages in thread
From: Maxin B. John @ 2014-03-06 21:41 UTC (permalink / raw)
  To: Greg KH
  Cc: Dan Carpenter, devel, andreas.dilger, Peng Tao, alexey.zhuravlev,
	Linux Kernel, Dulshani Gunawardhana, josh, jinshan.xiong,
	Maxin B. John

Hi,

On Thu, Mar 6, 2014 at 8:51 PM, Greg KH <gregkh@linuxfoundation.org> wrote:
> On Wed, Mar 05, 2014 at 09:53:06PM +0300, Dan Carpenter wrote:
>> On Wed, Mar 05, 2014 at 02:04:35PM +0100, Maxin B. John wrote:
>> > From: "Maxin B. John" <maxin.john@enea.com>
>> >
>> > cppcheck reported possible null pointer dereference in mdc_lib.c
>> >
>> > [lustre/lustre/mdc/mdc_lib.c:233]: (error) Possible null pointer dereference
>> > : op_data - otherwise it is redundant to check if op_data is null at line 226
>> >
>>
>> There is only one caller and "op_data" is not NULL.
>
> I agree, John, please fix your tools.  Or check the result and fix the
> code so that there isn't false-positives (by not checking for NULL at
> all here...)

Thanks to Dan and Greg for the comments. Will try my best to avoid
these kind of mistakes in future.

> thanks,
> greg k-h

Best Regards,
Maxin

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

end of thread, other threads:[~2014-03-06 21:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-05 13:04 [PATCH 1/2] lustre/mdc_lib: fix possible null pointer dereference Maxin B. John
2014-03-05 13:04 ` [PATCH 2/2] lustre/lov_obd: " Maxin B. John
2014-03-06 19:53   ` Greg KH
2014-03-05 18:53 ` [PATCH 1/2] lustre/mdc_lib: " Dan Carpenter
2014-03-06 19:51   ` Greg KH
2014-03-06 21:41     ` Maxin B. John

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