public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH 1/2] nvme-fc: avoid null pointer dereference
@ 2022-11-30 21:33 Chaitanya Kulkarni
  2022-11-30 21:33 ` [PATCH 2/2] nvme-fc: move common code into helper Chaitanya Kulkarni
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Chaitanya Kulkarni @ 2022-11-30 21:33 UTC (permalink / raw)
  To: linux-nvme; +Cc: james.smart, kbusch, hch, sagi, Chaitanya Kulkarni

Before using dynamically allcoated variable lsop in the
nvme_fc_rcv_ls_req(), add a check for NULL and error out early.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/nvme/host/fc.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
index 489f5e797204..06bae7150087 100644
--- a/drivers/nvme/host/fc.c
+++ b/drivers/nvme/host/fc.c
@@ -1754,9 +1754,18 @@ nvme_fc_rcv_ls_req(struct nvme_fc_remote_port *portptr,
 	}
 
 	lsop = kzalloc(sizeof(*lsop), GFP_KERNEL);
+	if (!lsop) {
+		dev_info(lport->dev,
+			"RCV %s LS failed: No memory\n",
+			(w0->ls_cmd <= NVME_FC_LAST_LS_CMD_VALUE) ?
+				nvmefc_ls_names[w0->ls_cmd] : "");
+		ret = -ENOMEM;
+		goto out_put;
+	}
+
 	lsop->rqstbuf = kzalloc(sizeof(*lsop->rqstbuf), GFP_KERNEL);
 	lsop->rspbuf = kzalloc(sizeof(*lsop->rspbuf), GFP_KERNEL);
-	if (!lsop || !lsop->rqstbuf || !lsop->rspbuf) {
+	if (!lsop->rqstbuf || !lsop->rspbuf) {
 		dev_info(lport->dev,
 			"RCV %s LS failed: No memory\n",
 			(w0->ls_cmd <= NVME_FC_LAST_LS_CMD_VALUE) ?
-- 
2.29.0



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

* [PATCH 2/2] nvme-fc: move common code into helper
  2022-11-30 21:33 [PATCH 1/2] nvme-fc: avoid null pointer dereference Chaitanya Kulkarni
@ 2022-11-30 21:33 ` Chaitanya Kulkarni
  2022-12-02 16:09   ` James Smart
  2022-12-02 16:07 ` [PATCH 1/2] nvme-fc: avoid null pointer dereference James Smart
  2022-12-06  8:08 ` Christoph Hellwig
  2 siblings, 1 reply; 5+ messages in thread
From: Chaitanya Kulkarni @ 2022-11-30 21:33 UTC (permalink / raw)
  To: linux-nvme; +Cc: james.smart, kbusch, hch, sagi, Chaitanya Kulkarni

Add a helper to move the duplicate code for error message
from nvme_fc_rcv_ls_req() to nvme_fc_rcv_ls_req_err_msg().

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/nvme/host/fc.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
index 06bae7150087..42fa450187f8 100644
--- a/drivers/nvme/host/fc.c
+++ b/drivers/nvme/host/fc.c
@@ -1701,6 +1701,15 @@ nvme_fc_handle_ls_rqst_work(struct work_struct *work)
 	spin_unlock_irqrestore(&rport->lock, flags);
 }
 
+static
+void nvme_fc_rcv_ls_req_err_msg(struct nvme_fc_lport *lport,
+				struct fcnvme_ls_rqst_w0 *w0)
+{
+	dev_info(lport->dev, "RCV %s LS failed: No memory\n",
+		(w0->ls_cmd <= NVME_FC_LAST_LS_CMD_VALUE) ?
+			nvmefc_ls_names[w0->ls_cmd] : "");
+}
+
 /**
  * nvme_fc_rcv_ls_req - transport entry point called by an LLDD
  *                       upon the reception of a NVME LS request.
@@ -1755,10 +1764,7 @@ nvme_fc_rcv_ls_req(struct nvme_fc_remote_port *portptr,
 
 	lsop = kzalloc(sizeof(*lsop), GFP_KERNEL);
 	if (!lsop) {
-		dev_info(lport->dev,
-			"RCV %s LS failed: No memory\n",
-			(w0->ls_cmd <= NVME_FC_LAST_LS_CMD_VALUE) ?
-				nvmefc_ls_names[w0->ls_cmd] : "");
+		nvme_fc_rcv_ls_req_err_msg(lport, w0);
 		ret = -ENOMEM;
 		goto out_put;
 	}
@@ -1766,10 +1772,7 @@ nvme_fc_rcv_ls_req(struct nvme_fc_remote_port *portptr,
 	lsop->rqstbuf = kzalloc(sizeof(*lsop->rqstbuf), GFP_KERNEL);
 	lsop->rspbuf = kzalloc(sizeof(*lsop->rspbuf), GFP_KERNEL);
 	if (!lsop->rqstbuf || !lsop->rspbuf) {
-		dev_info(lport->dev,
-			"RCV %s LS failed: No memory\n",
-			(w0->ls_cmd <= NVME_FC_LAST_LS_CMD_VALUE) ?
-				nvmefc_ls_names[w0->ls_cmd] : "");
+		nvme_fc_rcv_ls_req_err_msg(lport, w0);
 		ret = -ENOMEM;
 		goto out_free;
 	}
-- 
2.29.0



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

* Re: [PATCH 1/2] nvme-fc: avoid null pointer dereference
  2022-11-30 21:33 [PATCH 1/2] nvme-fc: avoid null pointer dereference Chaitanya Kulkarni
  2022-11-30 21:33 ` [PATCH 2/2] nvme-fc: move common code into helper Chaitanya Kulkarni
@ 2022-12-02 16:07 ` James Smart
  2022-12-06  8:08 ` Christoph Hellwig
  2 siblings, 0 replies; 5+ messages in thread
From: James Smart @ 2022-12-02 16:07 UTC (permalink / raw)
  To: Chaitanya Kulkarni, linux-nvme; +Cc: james.smart, kbusch, hch, sagi

On 11/30/2022 1:33 PM, Chaitanya Kulkarni wrote:
> Before using dynamically allcoated variable lsop in the
> nvme_fc_rcv_ls_req(), add a check for NULL and error out early.
> 
> Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
> ---
>   drivers/nvme/host/fc.c | 11 ++++++++++-
>   1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
> index 489f5e797204..06bae7150087 100644
> --- a/drivers/nvme/host/fc.c
> +++ b/drivers/nvme/host/fc.c
> @@ -1754,9 +1754,18 @@ nvme_fc_rcv_ls_req(struct nvme_fc_remote_port *portptr,
>   	}
>   
>   	lsop = kzalloc(sizeof(*lsop), GFP_KERNEL);
> +	if (!lsop) {
> +		dev_info(lport->dev,
> +			"RCV %s LS failed: No memory\n",
> +			(w0->ls_cmd <= NVME_FC_LAST_LS_CMD_VALUE) ?
> +				nvmefc_ls_names[w0->ls_cmd] : "");
> +		ret = -ENOMEM;
> +		goto out_put;
> +	}
> +
>   	lsop->rqstbuf = kzalloc(sizeof(*lsop->rqstbuf), GFP_KERNEL);
>   	lsop->rspbuf = kzalloc(sizeof(*lsop->rspbuf), GFP_KERNEL);
> -	if (!lsop || !lsop->rqstbuf || !lsop->rspbuf) {
> +	if (!lsop->rqstbuf || !lsop->rspbuf) {
>   		dev_info(lport->dev,
>   			"RCV %s LS failed: No memory\n",
>   			(w0->ls_cmd <= NVME_FC_LAST_LS_CMD_VALUE) ?

Looks good

Reviewed-by: James Smart <jsmart2021@gmail.com>

-- james



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

* Re: [PATCH 2/2] nvme-fc: move common code into helper
  2022-11-30 21:33 ` [PATCH 2/2] nvme-fc: move common code into helper Chaitanya Kulkarni
@ 2022-12-02 16:09   ` James Smart
  0 siblings, 0 replies; 5+ messages in thread
From: James Smart @ 2022-12-02 16:09 UTC (permalink / raw)
  To: Chaitanya Kulkarni, linux-nvme; +Cc: james.smart, kbusch, hch, sagi

On 11/30/2022 1:33 PM, Chaitanya Kulkarni wrote:
> Add a helper to move the duplicate code for error message
> from nvme_fc_rcv_ls_req() to nvme_fc_rcv_ls_req_err_msg().
> 
> Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
> ---
>   drivers/nvme/host/fc.c | 19 +++++++++++--------
>   1 file changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c
> index 06bae7150087..42fa450187f8 100644
> --- a/drivers/nvme/host/fc.c
> +++ b/drivers/nvme/host/fc.c
> @@ -1701,6 +1701,15 @@ nvme_fc_handle_ls_rqst_work(struct work_struct *work)
>   	spin_unlock_irqrestore(&rport->lock, flags);
>   }
>   
> +static
> +void nvme_fc_rcv_ls_req_err_msg(struct nvme_fc_lport *lport,
> +				struct fcnvme_ls_rqst_w0 *w0)
> +{
> +	dev_info(lport->dev, "RCV %s LS failed: No memory\n",
> +		(w0->ls_cmd <= NVME_FC_LAST_LS_CMD_VALUE) ?
> +			nvmefc_ls_names[w0->ls_cmd] : "");
> +}
> +
>   /**
>    * nvme_fc_rcv_ls_req - transport entry point called by an LLDD
>    *                       upon the reception of a NVME LS request.
> @@ -1755,10 +1764,7 @@ nvme_fc_rcv_ls_req(struct nvme_fc_remote_port *portptr,
>   
>   	lsop = kzalloc(sizeof(*lsop), GFP_KERNEL);
>   	if (!lsop) {
> -		dev_info(lport->dev,
> -			"RCV %s LS failed: No memory\n",
> -			(w0->ls_cmd <= NVME_FC_LAST_LS_CMD_VALUE) ?
> -				nvmefc_ls_names[w0->ls_cmd] : "");
> +		nvme_fc_rcv_ls_req_err_msg(lport, w0);
>   		ret = -ENOMEM;
>   		goto out_put;
>   	}
> @@ -1766,10 +1772,7 @@ nvme_fc_rcv_ls_req(struct nvme_fc_remote_port *portptr,
>   	lsop->rqstbuf = kzalloc(sizeof(*lsop->rqstbuf), GFP_KERNEL);
>   	lsop->rspbuf = kzalloc(sizeof(*lsop->rspbuf), GFP_KERNEL);
>   	if (!lsop->rqstbuf || !lsop->rspbuf) {
> -		dev_info(lport->dev,
> -			"RCV %s LS failed: No memory\n",
> -			(w0->ls_cmd <= NVME_FC_LAST_LS_CMD_VALUE) ?
> -				nvmefc_ls_names[w0->ls_cmd] : "");
> +		nvme_fc_rcv_ls_req_err_msg(lport, w0);
>   		ret = -ENOMEM;
>   		goto out_free;
>   	}

OK

Reviewed-by: James Smart <jsmart2021@gmail.com>

-- james




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

* Re: [PATCH 1/2] nvme-fc: avoid null pointer dereference
  2022-11-30 21:33 [PATCH 1/2] nvme-fc: avoid null pointer dereference Chaitanya Kulkarni
  2022-11-30 21:33 ` [PATCH 2/2] nvme-fc: move common code into helper Chaitanya Kulkarni
  2022-12-02 16:07 ` [PATCH 1/2] nvme-fc: avoid null pointer dereference James Smart
@ 2022-12-06  8:08 ` Christoph Hellwig
  2 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2022-12-06  8:08 UTC (permalink / raw)
  To: Chaitanya Kulkarni; +Cc: linux-nvme, james.smart, kbusch, hch, sagi

Thanks, applied both patches to nvme-6.2.


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

end of thread, other threads:[~2022-12-06  8:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-30 21:33 [PATCH 1/2] nvme-fc: avoid null pointer dereference Chaitanya Kulkarni
2022-11-30 21:33 ` [PATCH 2/2] nvme-fc: move common code into helper Chaitanya Kulkarni
2022-12-02 16:09   ` James Smart
2022-12-02 16:07 ` [PATCH 1/2] nvme-fc: avoid null pointer dereference James Smart
2022-12-06  8:08 ` Christoph Hellwig

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