Skip to contentSkip to conversation

usnic: corretly check failed allocation

PATCH In review Insu Yun 2 participants 3 messages Oct 15, 2015 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Insu Yun

author
#0 lore raw

PATCH 1/1 usnic: corretly check failed allocation

Since ib_alloc_device returns allocated memory address, not error, it should be checked as IS_NULL, not IS_ERR_OR_NULL.

---
 drivers/infiniband/hw/usnic/usnic_ib_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/hw/usnic/usnic_ib_main.c +2 -2
index 34c49b8..7c5f602 100644
@@ -328,14 +328,14 @@ static void *usnic_ib_device_add(struct pci_dev *dev)
 	netdev = pci_get_drvdata(dev);
 
 	us_ibdev = (struct usnic_ib_dev *)ib_alloc_device(sizeof(*us_ibdev));
-	if (IS_ERR_OR_NULL(us_ibdev)) {
+	if (!us_ibdev) {
 		usnic_err("Device %s context alloc failed\n",
 				netdev_name(pci_get_drvdata(dev)));
 		return ERR_PTR(us_ibdev ? PTR_ERR(us_ibdev) : -EFAULT);
 	}
 
 	us_ibdev->ufdev = usnic_fwd_dev_alloc(dev);
-	if (IS_ERR_OR_NULL(us_ibdev->ufdev)) {
+	if (!us_ibdev->ufdev) {
 		usnic_err("Failed to alloc ufdev for %s with err %ld\n",
 				pci_name(dev), PTR_ERR(us_ibdev->ufdev));
 		goto err_dealloc;
Signature · 1 line
1.9.1
#1 lore raw
Quoted 8 lines · Insu Yun

Since ib_alloc_device returns allocated memory address, not error, it should be checked as IS_NULL, not IS_ERR_OR_NULL.

---
drivers/infiniband/hw/usnic/usnic_ib_main.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)

There's a typo in the subject ("corretly"-->"correctly").

Out of curiosity, what led you to spot this? General code inspection or did this come out of some tool?

drivers/infiniband/hw/usnic/usnic_ib_main.c static void *usnic_ib_device_add(struct pci_dev *dev) · line 334

Quoted 13 lines
drivers/infiniband/hw/usnic/usnic_ib_main.c +1 -1
index 34c49b8..7c5f602 100644
@@ -328,14 +328,14 @@ static void *usnic_ib_device_add(struct pci_dev *dev)
 	netdev = pci_get_drvdata(dev);
 
 	us_ibdev = (struct usnic_ib_dev *)ib_alloc_device(sizeof(*us_ibdev));
-	if (IS_ERR_OR_NULL(us_ibdev)) {
+	if (!us_ibdev) {
 		usnic_err("Device %s context alloc failed\n",
 				netdev_name(pci_get_drvdata(dev)));
 		return ERR_PTR(us_ibdev ? PTR_ERR(us_ibdev) : -EFAULT);

I think this can become:

return ERR_PTR(-EFAULT);

drivers/infiniband/hw/usnic/usnic_ib_main.c static void *usnic_ib_device_add(struct pci_dev *dev) · line 340

Quoted 7 lines
drivers/infiniband/hw/usnic/usnic_ib_main.c +1 -1
 	}
 
 	us_ibdev->ufdev = usnic_fwd_dev_alloc(dev);
-	if (IS_ERR_OR_NULL(us_ibdev->ufdev)) {
+	if (!us_ibdev->ufdev) {
 		usnic_err("Failed to alloc ufdev for %s with err %ld\n",
 				pci_name(dev), PTR_ERR(us_ibdev->ufdev));

This PTR_ERR and message make less sense now.

-Dave

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to a message not in the archive
Quoted 11 lines · Insu Yun

On Thu, Oct 15, 2015 at 1:17 PM, Dave Goodell (dgoodell) <[email protected]

Quoted 10 lines

wrote:

Quoted 6 lines · Insu Yun
      us_ibdev->ufdev = usnic_fwd_dev_alloc(dev);
drivers/infiniband/hw/usnic/usnic_ib_main.c +1 -1
-     if (IS_ERR_OR_NULL(us_ibdev->ufdev)) {
+     if (!us_ibdev->ufdev) {
              usnic_err("Failed to alloc ufdev for %s with err %ld\n",
                              pci_name(dev), PTR_ERR(us_ibdev->ufdev));
Quoted 6 lines
Quoted 2 lines

This PTR_ERR and message make less sense now.

Do you think what is better? removing error code? or change
PTR_ERR(us_ibdev->ufdev)
to -EFAULT

I would write it as:

        usnic_err("Failed to alloc ufdev for %s\n", pci_name(dev));

-Dave
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html