linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] PATA-MacIO: Adjustments for five function implementations
@ 2018-02-16 12:37 SF Markus Elfring
  2018-02-16 12:38 ` [PATCH 1/3] pata_macio: Delete an error message for a failed memory allocation in two functions SF Markus Elfring
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: SF Markus Elfring @ 2018-02-16 12:37 UTC (permalink / raw)
  To: linux-ide, Bartlomiej Zolnierkiewicz, Tejun Heo; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 16 Feb 2018 13:32:23 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
  Delete an error message for a failed memory allocation in two functions
  Improve a size determination in two functions
  Adjust 11 checks for null pointers

 drivers/ata/pata_macio.c | 40 +++++++++++++++++-----------------------
 1 file changed, 17 insertions(+), 23 deletions(-)

-- 
2.16.1


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

* [PATCH 1/3] pata_macio: Delete an error message for a failed memory allocation in two functions
  2018-02-16 12:37 [PATCH 0/3] PATA-MacIO: Adjustments for five function implementations SF Markus Elfring
@ 2018-02-16 12:38 ` SF Markus Elfring
  2018-02-16 12:39 ` [PATCH 2/3] pata_macio: Improve a size determination " SF Markus Elfring
  2018-02-16 12:40 ` [PATCH 3/3] pata_macio: Adjust 11 checks for null pointers SF Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2018-02-16 12:38 UTC (permalink / raw)
  To: linux-ide, Bartlomiej Zolnierkiewicz, Tejun Heo; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 16 Feb 2018 13:01:45 +0100

Omit an extra message for a memory allocation failure in these functions.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/ata/pata_macio.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/ata/pata_macio.c b/drivers/ata/pata_macio.c
index 0adcb40d2794..9588e685d994 100644
--- a/drivers/ata/pata_macio.c
+++ b/drivers/ata/pata_macio.c
@@ -1131,11 +1131,9 @@ static int pata_macio_attach(struct macio_dev *mdev,
 	/* Allocate and init private data structure */
 	priv = devm_kzalloc(&mdev->ofdev.dev,
 			    sizeof(struct pata_macio_priv), GFP_KERNEL);
-	if (priv == NULL) {
-		dev_err(&mdev->ofdev.dev,
-			"Failed to allocate private memory\n");
+	if (!priv)
 		return -ENOMEM;
-	}
+
 	priv->node = of_node_get(mdev->ofdev.dev.of_node);
 	priv->mdev = mdev;
 	priv->dev = &mdev->ofdev.dev;
@@ -1277,11 +1275,9 @@ static int pata_macio_pci_attach(struct pci_dev *pdev,
 	/* Allocate and init private data structure */
 	priv = devm_kzalloc(&pdev->dev,
 			    sizeof(struct pata_macio_priv), GFP_KERNEL);
-	if (priv == NULL) {
-		dev_err(&pdev->dev,
-			"Failed to allocate private memory\n");
+	if (!priv)
 		return -ENOMEM;
-	}
+
 	priv->node = of_node_get(np);
 	priv->pdev = pdev;
 	priv->dev = &pdev->dev;
-- 
2.16.1


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

* [PATCH 2/3] pata_macio: Improve a size determination in two functions
  2018-02-16 12:37 [PATCH 0/3] PATA-MacIO: Adjustments for five function implementations SF Markus Elfring
  2018-02-16 12:38 ` [PATCH 1/3] pata_macio: Delete an error message for a failed memory allocation in two functions SF Markus Elfring
@ 2018-02-16 12:39 ` SF Markus Elfring
  2018-02-16 12:40 ` [PATCH 3/3] pata_macio: Adjust 11 checks for null pointers SF Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2018-02-16 12:39 UTC (permalink / raw)
  To: linux-ide, Bartlomiej Zolnierkiewicz, Tejun Heo; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 16 Feb 2018 13:08:14 +0100

Replace the specification of data structures by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/ata/pata_macio.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/ata/pata_macio.c b/drivers/ata/pata_macio.c
index 9588e685d994..dc40af4c615c 100644
--- a/drivers/ata/pata_macio.c
+++ b/drivers/ata/pata_macio.c
@@ -1129,8 +1129,7 @@ static int pata_macio_attach(struct macio_dev *mdev,
 	macio_enable_devres(mdev);
 
 	/* Allocate and init private data structure */
-	priv = devm_kzalloc(&mdev->ofdev.dev,
-			    sizeof(struct pata_macio_priv), GFP_KERNEL);
+	priv = devm_kzalloc(&mdev->ofdev.dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
 		return -ENOMEM;
 
@@ -1273,8 +1272,7 @@ static int pata_macio_pci_attach(struct pci_dev *pdev,
 	}
 
 	/* Allocate and init private data structure */
-	priv = devm_kzalloc(&pdev->dev,
-			    sizeof(struct pata_macio_priv), GFP_KERNEL);
+	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
 		return -ENOMEM;
 
-- 
2.16.1

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

* [PATCH 3/3] pata_macio: Adjust 11 checks for null pointers
  2018-02-16 12:37 [PATCH 0/3] PATA-MacIO: Adjustments for five function implementations SF Markus Elfring
  2018-02-16 12:38 ` [PATCH 1/3] pata_macio: Delete an error message for a failed memory allocation in two functions SF Markus Elfring
  2018-02-16 12:39 ` [PATCH 2/3] pata_macio: Improve a size determination " SF Markus Elfring
@ 2018-02-16 12:40 ` SF Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2018-02-16 12:40 UTC (permalink / raw)
  To: linux-ide, Bartlomiej Zolnierkiewicz, Tejun Heo; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 16 Feb 2018 13:20:03 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script “checkpatch.pl” pointed information out like the following.

Comparison to NULL could be written !…

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/ata/pata_macio.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/ata/pata_macio.c b/drivers/ata/pata_macio.c
index dc40af4c615c..04d546d672c0 100644
--- a/drivers/ata/pata_macio.c
+++ b/drivers/ata/pata_macio.c
@@ -405,23 +405,23 @@ static void pata_macio_set_timings(struct ata_port *ap,
 
 	/* Now get the PIO timings */
 	t = pata_macio_find_timing(priv, adev->pio_mode);
-	if (t == NULL) {
+	if (!t) {
 		dev_warn(priv->dev, "Invalid PIO timing requested: 0x%x\n",
 			 adev->pio_mode);
 		t = pata_macio_find_timing(priv, XFER_PIO_0);
 	}
-	BUG_ON(t == NULL);
+	BUG_ON(!t);
 
 	/* PIO timings only ever use the first treg */
 	priv->treg[adev->devno][0] |= t->reg1;
 
 	/* Now get DMA timings */
 	t = pata_macio_find_timing(priv, adev->dma_mode);
-	if (t == NULL || (t->reg1 == 0 && t->reg2 == 0)) {
+	if (!t || (t->reg1 == 0 && t->reg2 == 0)) {
 		dev_dbg(priv->dev, "DMA timing not set yet, using MW_DMA_0\n");
 		t = pata_macio_find_timing(priv, XFER_MW_DMA_0);
 	}
-	BUG_ON(t == NULL);
+	BUG_ON(!t);
 
 	/* DMA timings can use both tregs */
 	priv->treg[adev->devno][0] |= t->reg1;
@@ -705,7 +705,7 @@ static int pata_macio_port_start(struct ata_port *ap)
 {
 	struct pata_macio_priv *priv = ap->private_data;
 
-	if (ap->ioaddr.bmdma_addr == NULL)
+	if (!ap->ioaddr.bmdma_addr)
 		return 0;
 
 	/* Allocate space for the DBDMA commands.
@@ -717,7 +717,7 @@ static int pata_macio_port_start(struct ata_port *ap)
 		dmam_alloc_coherent(priv->dev,
 				    (MAX_DCMDS + 2) * sizeof(struct dbdma_cmd),
 				    &priv->dma_table_dma, GFP_KERNEL);
-	if (priv->dma_table_cpu == NULL) {
+	if (!priv->dma_table_cpu) {
 		dev_err(priv->dev, "Unable to allocate DMA command list\n");
 		ap->ioaddr.bmdma_addr = NULL;
 		ap->mwdma_mask = 0;
@@ -1055,7 +1055,7 @@ static int pata_macio_common_init(struct pata_macio_priv *priv,
 	pinfo.private_data	= priv;
 
 	priv->host = ata_host_alloc_pinfo(priv->dev, ppi, 1);
-	if (priv->host == NULL) {
+	if (!priv->host) {
 		dev_err(priv->dev, "Failed to allocate ATA port structure\n");
 		return -ENOMEM;
 	}
@@ -1065,7 +1065,7 @@ static int pata_macio_common_init(struct pata_macio_priv *priv,
 
 	/* Map base registers */
 	priv->tfregs = devm_ioremap(priv->dev, tfregs, 0x100);
-	if (priv->tfregs == NULL) {
+	if (!priv->tfregs) {
 		dev_err(priv->dev, "Failed to map ATA ports\n");
 		return -ENOMEM;
 	}
@@ -1075,14 +1075,14 @@ static int pata_macio_common_init(struct pata_macio_priv *priv,
 	if (dmaregs != 0) {
 		dma_regs = devm_ioremap(priv->dev, dmaregs,
 					sizeof(struct dbdma_regs));
-		if (dma_regs == NULL)
+		if (!dma_regs)
 			dev_warn(priv->dev, "Failed to map ATA DMA registers\n");
 	}
 
 	/* If chip has local feature control, map those regs too */
 	if (fcregs != 0) {
 		priv->kauai_fcr = devm_ioremap(priv->dev, fcregs, 4);
-		if (priv->kauai_fcr == NULL) {
+		if (!priv->kauai_fcr) {
 			dev_err(priv->dev, "Failed to map ATA FCR register\n");
 			return -ENOMEM;
 		}
@@ -1258,7 +1258,7 @@ static int pata_macio_pci_attach(struct pci_dev *pdev,
 
 	/* We cannot use a MacIO controller without its OF device node */
 	np = pci_device_to_OF_node(pdev);
-	if (np == NULL) {
+	if (!np) {
 		dev_err(&pdev->dev,
 			"Cannot find OF device node for controller\n");
 		return -ENODEV;
-- 
2.16.1

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

end of thread, other threads:[~2018-02-16 12:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-16 12:37 [PATCH 0/3] PATA-MacIO: Adjustments for five function implementations SF Markus Elfring
2018-02-16 12:38 ` [PATCH 1/3] pata_macio: Delete an error message for a failed memory allocation in two functions SF Markus Elfring
2018-02-16 12:39 ` [PATCH 2/3] pata_macio: Improve a size determination " SF Markus Elfring
2018-02-16 12:40 ` [PATCH 3/3] pata_macio: Adjust 11 checks for null pointers SF Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).