[PATCH] bfa: fix leak of bfad_im_port_index on module unload

2015-06-11 Thread Alexey Khoroshilov
Resources allocated within bfad_im_port_index idr are not deallocated
on module unload. The patch adds idr_destroy() in exit function.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov 
---
 drivers/scsi/bfa/bfad_im.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/scsi/bfa/bfad_im.c b/drivers/scsi/bfa/bfad_im.c
index 7223b0006740..8367c11d554b 100644
--- a/drivers/scsi/bfa/bfad_im.c
+++ b/drivers/scsi/bfa/bfad_im.c
@@ -851,6 +851,8 @@ bfad_im_module_exit(void)
 
if (bfad_im_scsi_vport_transport_template)
fc_release_transport(bfad_im_scsi_vport_transport_template);
+
+   idr_destroy(&bfad_im_port_index);
 }
 
 void
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] wd719x: add check for dma mapping errors

2017-01-27 Thread Alexey Khoroshilov
wd719x_queuecommand() doesn't check if mapping dma memory succeed.
The patch adds the check and failure handling.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov 
---
 drivers/scsi/wd719x.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/scsi/wd719x.c b/drivers/scsi/wd719x.c
index 2a9da2e0ea6b..41ddbdcf02e0 100644
--- a/drivers/scsi/wd719x.c
+++ b/drivers/scsi/wd719x.c
@@ -244,6 +244,12 @@ static int wd719x_queuecommand(struct Scsi_Host *sh, 
struct scsi_cmnd *cmd)
scb->sense_buf_length = SCSI_SENSE_BUFFERSIZE;
cmd->SCp.dma_handle = dma_map_single(&wd->pdev->dev, cmd->sense_buffer,
SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
+   if (dma_mapping_error(&wd->pdev->dev, cmd->SCp.dma_handle)) {
+   dev_err(&wd->pdev->dev, "unable to map dma\n");
+   wd719x_finish_cmd(cmd, DID_ERROR);
+   spin_unlock_irqrestore(wd->sh->host_lock, flags);
+   return 0;
+   }
scb->sense_buf = cpu_to_le32(cmd->SCp.dma_handle);
 
/* request autosense */
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] mptsas: fix checks for dma mapping errors

2016-04-15 Thread Alexey Khoroshilov
mptsas_smp_handler() checks for dma mapping errors by comparison
returned address with zero, while pci_dma_mapping_error() should be used.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov 
---
 drivers/message/fusion/mptsas.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index 7ebccfa8072a..7ee1667acde4 100644
--- a/drivers/message/fusion/mptsas.c
+++ b/drivers/message/fusion/mptsas.c
@@ -2281,7 +2281,7 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, 
struct sas_rphy *rphy,
 
dma_addr_out = pci_map_single(ioc->pcidev, bio_data(req->bio),
  blk_rq_bytes(req), PCI_DMA_BIDIRECTIONAL);
-   if (!dma_addr_out)
+   if (pci_dma_mapping_error(ioc->pcidev, dma_addr_out))
goto put_mf;
ioc->add_sge(psge, flagsLength, dma_addr_out);
psge += ioc->SGE_size;
@@ -2296,7 +2296,7 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, 
struct sas_rphy *rphy,
flagsLength |= blk_rq_bytes(rsp) + 4;
dma_addr_in =  pci_map_single(ioc->pcidev, bio_data(rsp->bio),
  blk_rq_bytes(rsp), PCI_DMA_BIDIRECTIONAL);
-   if (!dma_addr_in)
+   if (pci_dma_mapping_error(ioc->pcidev, dma_addr_in))
goto unmap;
ioc->add_sge(psge, flagsLength, dma_addr_in);
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] megaraid: fix error code check of register_chrdev()

2016-05-13 Thread Alexey Khoroshilov
There is invalid error code check of register_chrdev() in megaraid_init().

register_chrdev() returns negative code in case of error,
as a result current code can try to unregister_chrdev() with error code
instead of major that may lead to unregistering somebody else's chardev.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov 
---
 drivers/scsi/megaraid.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 9d05302a3bcd..ded082942ca0 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -4702,7 +4702,7 @@ static int __init megaraid_init(void)
 * major number allocation.
 */
major = register_chrdev(0, "megadev_legacy", &megadev_fops);
-   if (!major) {
+   if (major < 0) {
printk(KERN_WARNING
"megaraid: failed to register char device\n");
}
@@ -4715,7 +4715,10 @@ static void __exit megaraid_exit(void)
/*
 * Unregister the character device interface to the driver.
 */
-   unregister_chrdev(major, "megadev_legacy");
+   if (major > 0) {
+   unregister_chrdev(major, "megadev_legacy");
+   major = 0;
+   }
 
pci_unregister_driver(&megaraid_pci_driver);
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] [SCSI] scsi_dh_hp_sw: return -ENOMEM if kzalloc() failed

2013-02-22 Thread Alexey Khoroshilov
If kzalloc() failed, hp_sw_bus_attach() breaks off initialization, but returns 
zero.
The patch adds -ENOMEM as return value in this case.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov 
---
 drivers/scsi/device_handler/scsi_dh_hp_sw.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/device_handler/scsi_dh_hp_sw.c 
b/drivers/scsi/device_handler/scsi_dh_hp_sw.c
index 084062b..4619473 100644
--- a/drivers/scsi/device_handler/scsi_dh_hp_sw.c
+++ b/drivers/scsi/device_handler/scsi_dh_hp_sw.c
@@ -364,7 +364,7 @@ static int hp_sw_bus_attach(struct scsi_device *sdev)
if (!scsi_dh_data) {
sdev_printk(KERN_ERR, sdev, "%s: Attach Failed\n",
HP_SW_NAME);
-   return 0;
+   return -ENOMEM;
}
 
scsi_dh_data->scsi_dh = &hp_sw_dh;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] mptlan: add checks for dma mapping errors

2016-01-22 Thread Alexey Khoroshilov
mpt_lan_sdu_send() and mpt_lan_post_receive_buckets() do not check
if mapping dma memory succeed.
The patch adds the checks and failure handling.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov 
---
 drivers/message/fusion/mptlan.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/drivers/message/fusion/mptlan.c b/drivers/message/fusion/mptlan.c
index cbe96072a6cc..076bf45a95fe 100644
--- a/drivers/message/fusion/mptlan.c
+++ b/drivers/message/fusion/mptlan.c
@@ -734,6 +734,12 @@ mpt_lan_sdu_send (struct sk_buff *skb, struct net_device 
*dev)
 
 dma = pci_map_single(mpt_dev->pcidev, skb->data, skb->len,
 PCI_DMA_TODEVICE);
+   if (dma_mapping_error(mpt_dev->pcidev, dma)) {
+   netif_stop_queue(dev);
+
+   printk (KERN_ERR "%s: dma mapping failed\n", __func__);
+   return NETDEV_TX_BUSY;
+   }
 
priv->SendCtl[ctx].skb = skb;
priv->SendCtl[ctx].dma = dma;
@@ -1232,6 +1238,14 @@ mpt_lan_post_receive_buckets(struct mpt_lan_priv *priv)
 
dma = pci_map_single(mpt_dev->pcidev, skb->data,
 len, PCI_DMA_FROMDEVICE);
+   if (pci_dma_mapping_error(mpt_dev->pcidev, 
dma)) {
+   printk (KERN_WARNING
+   MYNAM "/%s: dma mapping 
failed\n",
+   __func__);
+   
priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = ctx;
+   
spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
+   break;
+   }
 
priv->RcvCtl[ctx].skb = skb;
priv->RcvCtl[ctx].dma = dma;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] mptlan: add checks for dma mapping errors

2016-01-22 Thread Alexey Khoroshilov
mpt_lan_sdu_send() and mpt_lan_post_receive_buckets() do not check
if mapping dma memory succeed.
The patch adds the checks and failure handling.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov 
---
 drivers/message/fusion/mptlan.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/drivers/message/fusion/mptlan.c b/drivers/message/fusion/mptlan.c
index cbe96072a6cc..3b6c8a755713 100644
--- a/drivers/message/fusion/mptlan.c
+++ b/drivers/message/fusion/mptlan.c
@@ -734,6 +734,12 @@ mpt_lan_sdu_send (struct sk_buff *skb, struct net_device 
*dev)
 
 dma = pci_map_single(mpt_dev->pcidev, skb->data, skb->len,
 PCI_DMA_TODEVICE);
+   if (pci_dma_mapping_error(mpt_dev->pcidev, dma)) {
+   netif_stop_queue(dev);
+
+   printk (KERN_ERR "%s: dma mapping failed\n", __func__);
+   return NETDEV_TX_BUSY;
+   }
 
priv->SendCtl[ctx].skb = skb;
priv->SendCtl[ctx].dma = dma;
@@ -1232,6 +1238,14 @@ mpt_lan_post_receive_buckets(struct mpt_lan_priv *priv)
 
dma = pci_map_single(mpt_dev->pcidev, skb->data,
 len, PCI_DMA_FROMDEVICE);
+   if (pci_dma_mapping_error(mpt_dev->pcidev, 
dma)) {
+   printk (KERN_WARNING
+   MYNAM "/%s: dma mapping 
failed\n",
+   __func__);
+   
priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = ctx;
+   
spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
+   break;
+   }
 
priv->RcvCtl[ctx].skb = skb;
priv->RcvCtl[ctx].dma = dma;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2] mptlan: add checks for dma mapping errors

2016-01-25 Thread Alexey Khoroshilov
On 25.01.2016 16:36, Tomas Henzl wrote:
> On 23.1.2016 01:41, Alexey Khoroshilov wrote:
>> mpt_lan_sdu_send() and mpt_lan_post_receive_buckets() do not check
>> if mapping dma memory succeed.
>> The patch adds the checks and failure handling.
>>
>> Found by Linux Driver Verification project (linuxtesting.org).
>>
>> Signed-off-by: Alexey Khoroshilov 
>> ---
>>  drivers/message/fusion/mptlan.c | 14 ++
>>  1 file changed, 14 insertions(+)
>>
>> diff --git a/drivers/message/fusion/mptlan.c 
>> b/drivers/message/fusion/mptlan.c
>> index cbe96072a6cc..3b6c8a755713 100644
>> --- a/drivers/message/fusion/mptlan.c
>> +++ b/drivers/message/fusion/mptlan.c
>> @@ -734,6 +734,12 @@ mpt_lan_sdu_send (struct sk_buff *skb, struct 
>> net_device *dev)
>>  
>>  dma = pci_map_single(mpt_dev->pcidev, skb->data, skb->len,
>>   PCI_DMA_TODEVICE);
>> +if (pci_dma_mapping_error(mpt_dev->pcidev, dma)) {
>> +netif_stop_queue(dev);
> 
> Hi Alexey,
> isn't a mpt_put_msg_frame needed here ?
> and a similar de-alloc in next chunk too?
> -tms

Hi Tomas,

You are right, thank you!
I'll resend the patch.

--
Alexey

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3] mptlan: add checks for dma mapping errors

2016-01-25 Thread Alexey Khoroshilov
mpt_lan_sdu_send() and mpt_lan_post_receive_buckets() do not check
if mapping dma memory succeed.
The patch adds the checks and failure handling.

v3: Fix resource deallocation (reported by Tomas Henzl).

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov 
---
 drivers/message/fusion/mptlan.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/drivers/message/fusion/mptlan.c b/drivers/message/fusion/mptlan.c
index cbe96072a6cc..e9b83fc7be35 100644
--- a/drivers/message/fusion/mptlan.c
+++ b/drivers/message/fusion/mptlan.c
@@ -734,6 +734,13 @@ mpt_lan_sdu_send (struct sk_buff *skb, struct net_device 
*dev)
 
 dma = pci_map_single(mpt_dev->pcidev, skb->data, skb->len,
 PCI_DMA_TODEVICE);
+   if (pci_dma_mapping_error(mpt_dev->pcidev, dma)) {
+   mpt_put_msg_frame(LanCtx, mpt_dev, mf);
+   netif_stop_queue(dev);
+
+   printk (KERN_ERR "%s: dma mapping failed\n", __func__);
+   return NETDEV_TX_BUSY;
+   }
 
priv->SendCtl[ctx].skb = skb;
priv->SendCtl[ctx].dma = dma;
@@ -1232,6 +1239,15 @@ mpt_lan_post_receive_buckets(struct mpt_lan_priv *priv)
 
dma = pci_map_single(mpt_dev->pcidev, skb->data,
 len, PCI_DMA_FROMDEVICE);
+   if (pci_dma_mapping_error(mpt_dev->pcidev, 
dma)) {
+   printk (KERN_WARNING
+   MYNAM "/%s: dma mapping 
failed\n",
+   __func__);
+   dev_kfree_skb(skb);
+   
priv->mpt_rxfidx[++priv->mpt_rxfidx_tail] = ctx;
+   
spin_unlock_irqrestore(&priv->rxfidx_lock, flags);
+   break;
+   }
 
priv->RcvCtl[ctx].skb = skb;
priv->RcvCtl[ctx].dma = dma;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] [SCSI] bfa: allocate memory with GFP_ATOMIC in spinlock context

2014-04-18 Thread Alexey Khoroshilov
bfa_fcb_pbc_vport_create() is called only from bfa_fcs_pbc_vport_init(),
that is called only from bfad_drv_start() with bfad_lock spinlock held.
So the patch replaces GFP_KERNEL with GFP_ATOMIC to avoid
sleeping in atomic spinlock context.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov 
---
 drivers/scsi/bfa/bfad.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/bfa/bfad.c b/drivers/scsi/bfa/bfad.c
index cc0fbcdc5192..8f46d1b72fb8 100644
--- a/drivers/scsi/bfa/bfad.c
+++ b/drivers/scsi/bfa/bfad.c
@@ -652,7 +652,7 @@ bfad_vport_create(struct bfad_s *bfad, u16 vf_id,
unsigned long   flags;
struct completion fcomp;
 
-   vport = kzalloc(sizeof(struct bfad_vport_s), GFP_KERNEL);
+   vport = kzalloc(sizeof(struct bfad_vport_s), GFP_ATOMIC);
if (!vport) {
rc = BFA_STATUS_ENOMEM;
goto ext;
-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] [SCSI] bfa: allocate memory with GFP_ATOMIC in spinlock context

2014-04-18 Thread Alexey Khoroshilov
Please ignore this patch, it will resend a correct version of it.

On 18.04.2014 00:25, Alexey Khoroshilov wrote:
> bfa_fcb_pbc_vport_create() is called only from bfa_fcs_pbc_vport_init(),
> that is called only from bfad_drv_start() with bfad_lock spinlock held.
> So the patch replaces GFP_KERNEL with GFP_ATOMIC to avoid
> sleeping in atomic spinlock context.
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Alexey Khoroshilov 
> ---
>  drivers/scsi/bfa/bfad.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/bfa/bfad.c b/drivers/scsi/bfa/bfad.c
> index cc0fbcdc5192..8f46d1b72fb8 100644
> --- a/drivers/scsi/bfa/bfad.c
> +++ b/drivers/scsi/bfa/bfad.c
> @@ -652,7 +652,7 @@ bfad_vport_create(struct bfad_s *bfad, u16 vf_id,
>   unsigned long   flags;
>   struct completion fcomp;
>  
> - vport = kzalloc(sizeof(struct bfad_vport_s), GFP_KERNEL);
> + vport = kzalloc(sizeof(struct bfad_vport_s), GFP_ATOMIC);
>   if (!vport) {
>   rc = BFA_STATUS_ENOMEM;
>   goto ext;

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] [SCSI] bfa: allocate memory with GFP_ATOMIC in spinlock context

2014-04-18 Thread Alexey Khoroshilov
bfa_fcb_pbc_vport_create() is called only from bfa_fcs_pbc_vport_init(),
that is called only from bfad_drv_start() with bfad_lock spinlock held.
So the patch replaces GFP_KERNEL with GFP_ATOMIC to avoid
sleeping in atomic spinlock context.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov 
---
 drivers/scsi/bfa/bfad.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/bfa/bfad.c b/drivers/scsi/bfa/bfad.c
index cc0fbcdc5192..7593b7c1d336 100644
--- a/drivers/scsi/bfa/bfad.c
+++ b/drivers/scsi/bfa/bfad.c
@@ -507,7 +507,7 @@ bfa_fcb_pbc_vport_create(struct bfad_s *bfad, struct 
bfi_pbc_vport_s pbc_vport)
struct bfad_vport_s   *vport;
int rc;
 
-   vport = kzalloc(sizeof(struct bfad_vport_s), GFP_KERNEL);
+   vport = kzalloc(sizeof(struct bfad_vport_s), GFP_ATOMIC);
if (!vport) {
bfa_trc(bfad, 0);
return;
-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RESEND PATCH] [SCSI] mpt2sas: fix double mutex lock in NON_BLOCKING state

2012-08-24 Thread Alexey Khoroshilov
If state is NON_BLOCKING and mutex_trylock is succeed,
the control flow goes to mutex_lock_interruptible() that is a deadlock.

Found by Linux Driver Verification project (linuxtesting.org).

Acked-by: "Nandigama, Nagalakshmi" 
Signed-off-by: Alexey Khoroshilov 
---
 drivers/scsi/mpt2sas/mpt2sas_ctl.c |6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/mpt2sas/mpt2sas_ctl.c 
b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
index 49bdd2d..d29ea56 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_ctl.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
@@ -2181,8 +2181,10 @@ _ctl_ioctl_main(struct file *file, unsigned int cmd, 
void __user *arg,
return -EAGAIN;
 
state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING : BLOCKING;
-   if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex))
-   return -EAGAIN;
+   if (state == NON_BLOCKING) {
+   if (!mutex_trylock(&ioc->ctl_cmds.mutex))
+   return -EAGAIN;
+   }
else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
return -ERESTARTSYS;
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] [SCSI] mpt2sas: fix double mutex lock in NON_BLOCKING state

2012-08-28 Thread Alexey Khoroshilov
If state is NON_BLOCKING and mutex_trylock is succeed,
the control flow goes to mutex_lock_interruptible() that is a deadlock.

The previous version of the patch becomes obsolete after 
code movement in commit 913809f6.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov 
---
 drivers/scsi/mpt2sas/mpt2sas_ctl.c |6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/mpt2sas/mpt2sas_ctl.c 
b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
index 49bdd2d..d29ea56 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_ctl.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
@@ -2181,8 +2181,10 @@ _ctl_ioctl_main(struct file *file, unsigned int cmd, 
void __user *arg,
return -EAGAIN;
 
state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING : BLOCKING;
-   if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex))
-   return -EAGAIN;
+   if (state == NON_BLOCKING) {
+   if (!mutex_trylock(&ioc->ctl_cmds.mutex))
+   return -EAGAIN;
+   }
else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
return -ERESTARTSYS;
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: mvumi: add check for dma mapping errors

2017-04-21 Thread Alexey Khoroshilov
mvumi_make_sgl() does not check if mapping dma memory succeed.

The patch adds return error code if the mapping failed and
if scsi_bufflen(scmd) is zero. The latter is just in case
since the only call site of mvumi_make_sgl() check the scsi_bufflen(scmd)
before the call.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov 
---
 drivers/scsi/mvumi.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 247df5e79b71..49f8b20f5d91 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -232,11 +232,14 @@ static int mvumi_make_sgl(struct mvumi_hba *mhba, struct 
scsi_cmnd *scmd,
sgd_inc(mhba, m_sg);
}
} else {
-   scmd->SCp.dma_handle = scsi_bufflen(scmd) ?
-   pci_map_single(mhba->pdev, scsi_sglist(scmd),
-   scsi_bufflen(scmd),
-   (int) scmd->sc_data_direction)
-   : 0;
+   if (!scsi_bufflen(scmd))
+   return -1;
+   scmd->SCp.dma_handle = pci_map_single(mhba->pdev,
+   scsi_sglist(scmd),
+   scsi_bufflen(scmd),
+   (int) scmd->sc_data_direction);
+   if (pci_dma_mapping_error(mhba->pdev, scmd->SCp.dma_handle))
+   return -1;
busaddr = scmd->SCp.dma_handle;
m_sg->baseaddr_l = cpu_to_le32(lower_32_bits(busaddr));
m_sg->baseaddr_h = cpu_to_le32(upper_32_bits(busaddr));
-- 
2.7.4



[PATCH] scsi: mvumi: remove code handling zero scsi_sg_count(scmd) case

2017-04-23 Thread Alexey Khoroshilov
As Christoph Hellwig noted, SCSI commands that transfer data
always have a SG entry. The patch removes dead code in
mvumi_make_sgl(),  mvumi_complete_cmd() and mvumi_timed_out()
that handle zero scsi_sg_count(scmd) case.

Also the patch adds pci_unmap_sg() on failure path in mvumi_make_sgl().

Signed-off-by: Alexey Khoroshilov 
---
 drivers/scsi/mvumi.c | 85 
 1 file changed, 26 insertions(+), 59 deletions(-)

diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 247df5e79b71..fe97401ad192 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -210,39 +210,27 @@ static int mvumi_make_sgl(struct mvumi_hba *mhba, struct 
scsi_cmnd *scmd,
unsigned int sgnum = scsi_sg_count(scmd);
dma_addr_t busaddr;
 
-   if (sgnum) {
-   sg = scsi_sglist(scmd);
-   *sg_count = pci_map_sg(mhba->pdev, sg, sgnum,
-   (int) scmd->sc_data_direction);
-   if (*sg_count > mhba->max_sge) {
-   dev_err(&mhba->pdev->dev, "sg count[0x%x] is bigger "
-   "than max sg[0x%x].\n",
-   *sg_count, mhba->max_sge);
-   return -1;
-   }
-   for (i = 0; i < *sg_count; i++) {
-   busaddr = sg_dma_address(&sg[i]);
-   m_sg->baseaddr_l = cpu_to_le32(lower_32_bits(busaddr));
-   m_sg->baseaddr_h = cpu_to_le32(upper_32_bits(busaddr));
-   m_sg->flags = 0;
-   sgd_setsz(mhba, m_sg, cpu_to_le32(sg_dma_len(&sg[i])));
-   if ((i + 1) == *sg_count)
-   m_sg->flags |= 1U << mhba->eot_flag;
-
-   sgd_inc(mhba, m_sg);
-   }
-   } else {
-   scmd->SCp.dma_handle = scsi_bufflen(scmd) ?
-   pci_map_single(mhba->pdev, scsi_sglist(scmd),
-   scsi_bufflen(scmd),
-   (int) scmd->sc_data_direction)
-   : 0;
-   busaddr = scmd->SCp.dma_handle;
+   sg = scsi_sglist(scmd);
+   *sg_count = pci_map_sg(mhba->pdev, sg, sgnum,
+  (int) scmd->sc_data_direction);
+   if (*sg_count > mhba->max_sge) {
+   dev_err(&mhba->pdev->dev,
+   "sg count[0x%x] is bigger than max sg[0x%x].\n",
+   *sg_count, mhba->max_sge);
+   pci_unmap_sg(mhba->pdev, sg, sgnum,
+(int) scmd->sc_data_direction);
+   return -1;
+   }
+   for (i = 0; i < *sg_count; i++) {
+   busaddr = sg_dma_address(&sg[i]);
m_sg->baseaddr_l = cpu_to_le32(lower_32_bits(busaddr));
m_sg->baseaddr_h = cpu_to_le32(upper_32_bits(busaddr));
-   m_sg->flags = 1U << mhba->eot_flag;
-   sgd_setsz(mhba, m_sg, cpu_to_le32(scsi_bufflen(scmd)));
-   *sg_count = 1;
+   m_sg->flags = 0;
+   sgd_setsz(mhba, m_sg, cpu_to_le32(sg_dma_len(&sg[i])));
+   if ((i + 1) == *sg_count)
+   m_sg->flags |= 1U << mhba->eot_flag;
+
+   sgd_inc(mhba, m_sg);
}
 
return 0;
@@ -1350,21 +1338,10 @@ static void mvumi_complete_cmd(struct mvumi_hba *mhba, 
struct mvumi_cmd *cmd,
break;
}
 
-   if (scsi_bufflen(scmd)) {
-   if (scsi_sg_count(scmd)) {
-   pci_unmap_sg(mhba->pdev,
-   scsi_sglist(scmd),
-   scsi_sg_count(scmd),
-   (int) scmd->sc_data_direction);
-   } else {
-   pci_unmap_single(mhba->pdev,
-   scmd->SCp.dma_handle,
-   scsi_bufflen(scmd),
-   (int) scmd->sc_data_direction);
-
-   scmd->SCp.dma_handle = 0;
-   }
-   }
+   if (scsi_bufflen(scmd))
+   pci_unmap_sg(mhba->pdev, scsi_sglist(scmd),
+scsi_sg_count(scmd),
+(int) scmd->sc_data_direction);
cmd->scmd->scsi_done(scmd);
mvumi_return_cmd(mhba, cmd);
 }
@@ -2171,19 +2148,9 @@ static enum blk_eh_timer_return mvumi_timed_out(struct 
scsi_cmnd *scmd)
scmd->result = (DRIVER_INVALID << 24) | (DID_ABORT << 16);
scmd->SCp.ptr = NULL;
if (scsi_bufflen(scmd)) {
-   if (scsi_sg_count(scmd)) {
-   pci_unmap_sg(mhba->pdev,
- 

[PATCH] aic94xx: don't return zero on failure paths in aic94xx_init()

2018-05-18 Thread Alexey Khoroshilov
If sas_domain_attach_transport() fails in aic94xx_init(),
it breaks off initialization, deallocates all resources, but returns zero.

The patch adds -ENOMEM as return value in this case.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Peter Melnichenko 
Signed-off-by: Alexey Khoroshilov 
---
 drivers/scsi/aic94xx/aic94xx_init.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/aic94xx/aic94xx_init.c 
b/drivers/scsi/aic94xx/aic94xx_init.c
index 6c838865ac5a..4a4746cc6745 100644
--- a/drivers/scsi/aic94xx/aic94xx_init.c
+++ b/drivers/scsi/aic94xx/aic94xx_init.c
@@ -1030,8 +1030,10 @@ static int __init aic94xx_init(void)
 
aic94xx_transport_template =
sas_domain_attach_transport(&aic94xx_transport_functions);
-   if (!aic94xx_transport_template)
+   if (!aic94xx_transport_template) {
+   err = -ENOMEM;
goto out_destroy_caches;
+   }
 
err = pci_register_driver(&aic94xx_pci_driver);
if (err)
-- 
2.7.4