linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] FireWire-OHCI: Fine-tuning for some function implementations
@ 2017-04-20 20:24 SF Markus Elfring
  2017-04-20 20:26 ` [PATCH 1/2] firewire: ohci: Use kcalloc() in pci_probe() SF Markus Elfring
  2017-04-20 20:28 ` [PATCH 2/2] firewire: ohci: Adjust 15 checks for null pointers SF Markus Elfring
  0 siblings, 2 replies; 3+ messages in thread
From: SF Markus Elfring @ 2017-04-20 20:24 UTC (permalink / raw)
  To: linux1394-devel, Stefan Richter; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 20 Apr 2017 22:22:10 +0200

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

Markus Elfring (2):
  Use kcalloc() in pci_probe()
  Adjust 15 checks for null pointers

 drivers/firewire/ohci.c | 41 ++++++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 21 deletions(-)

-- 
2.12.2

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

* [PATCH 1/2] firewire: ohci: Use kcalloc() in pci_probe()
  2017-04-20 20:24 [PATCH 0/2] FireWire-OHCI: Fine-tuning for some function implementations SF Markus Elfring
@ 2017-04-20 20:26 ` SF Markus Elfring
  2017-04-20 20:28 ` [PATCH 2/2] firewire: ohci: Adjust 15 checks for null pointers SF Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: SF Markus Elfring @ 2017-04-20 20:26 UTC (permalink / raw)
  To: linux1394-devel, Stefan Richter; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 20 Apr 2017 21:50:19 +0200

* Multiplications for the size determination of memory allocations
  indicated that array data structures should be processed.
  Thus use the corresponding function "kcalloc".

  This issue was detected by using the Coccinelle software.

* Replace the specification of data structures by pointer dereferences
  to make the corresponding size determination a bit safer according to
  the Linux coding style convention.

* Delete the local variable "size" which became unnecessary
  with this refactoring.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/firewire/ohci.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
index 8bf89267dc25..30be5dbd5b09 100644
--- a/drivers/firewire/ohci.c
+++ b/drivers/firewire/ohci.c
@@ -3565,7 +3565,6 @@ static int pci_probe(struct pci_dev *dev,
 	u32 bus_options, max_receive, link_speed, version;
 	u64 guid;
 	int i, err;
-	size_t size;
 
 	if (dev->vendor == PCI_VENDOR_ID_PINNACLE_SYSTEMS) {
 		dev_err(&dev->dev, "Pinnacle MovieBoard is not yet supported\n");
@@ -3671,9 +3670,9 @@ static int pci_probe(struct pci_dev *dev,
 	reg_write(ohci, OHCI1394_IsoRecvIntMaskClear, ~0);
 	ohci->ir_context_mask = ohci->ir_context_support;
 	ohci->n_ir = hweight32(ohci->ir_context_mask);
-	size = sizeof(struct iso_context) * ohci->n_ir;
-	ohci->ir_context_list = kzalloc(size, GFP_KERNEL);
-
+	ohci->ir_context_list = kcalloc(ohci->n_ir,
+					sizeof(*ohci->ir_context_list),
+					GFP_KERNEL);
 	reg_write(ohci, OHCI1394_IsoXmitIntMaskSet, ~0);
 	ohci->it_context_support = reg_read(ohci, OHCI1394_IsoXmitIntMaskSet);
 	/* JMicron JMB38x often shows 0 at first read, just ignore it */
@@ -3684,9 +3683,9 @@ static int pci_probe(struct pci_dev *dev,
 	reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, ~0);
 	ohci->it_context_mask = ohci->it_context_support;
 	ohci->n_it = hweight32(ohci->it_context_mask);
-	size = sizeof(struct iso_context) * ohci->n_it;
-	ohci->it_context_list = kzalloc(size, GFP_KERNEL);
-
+	ohci->it_context_list = kcalloc(ohci->n_it,
+					sizeof(*ohci->it_context_list),
+					GFP_KERNEL);
 	if (ohci->it_context_list == NULL || ohci->ir_context_list == NULL) {
 		err = -ENOMEM;
 		goto fail_contexts;
-- 
2.12.2

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

* [PATCH 2/2] firewire: ohci: Adjust 15 checks for null pointers
  2017-04-20 20:24 [PATCH 0/2] FireWire-OHCI: Fine-tuning for some function implementations SF Markus Elfring
  2017-04-20 20:26 ` [PATCH 1/2] firewire: ohci: Use kcalloc() in pci_probe() SF Markus Elfring
@ 2017-04-20 20:28 ` SF Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: SF Markus Elfring @ 2017-04-20 20:28 UTC (permalink / raw)
  To: linux1394-devel, Stefan Richter; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 20 Apr 2017 22:10:29 +0200
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/firewire/ohci.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
index 30be5dbd5b09..165600c74b7c 100644
--- a/drivers/firewire/ohci.c
+++ b/drivers/firewire/ohci.c
@@ -1305,7 +1305,7 @@ static int at_context_queue_packet(struct context *ctx,
 	int z, tcode;
 
 	d = context_get_descriptors(ctx, 4, &d_bus);
-	if (d == NULL) {
+	if (!d) {
 		packet->ack = RCODE_SEND_ERROR;
 		return -1;
 	}
@@ -1450,7 +1450,7 @@ static int handle_at_packet(struct context *context,
 
 	driver_data = (struct driver_data *) &d[3];
 	packet = driver_data->packet;
-	if (packet == NULL)
+	if (!packet)
 		/* This packet was cancelled, just continue. */
 		return 1;
 
@@ -2027,7 +2027,7 @@ static void bus_reset_work(struct work_struct *work)
 	 * next_config_rom pointer so a new update can take place.
 	 */
 
-	if (ohci->next_config_rom != NULL) {
+	if (ohci->next_config_rom) {
 		if (ohci->next_config_rom != ohci->config_rom) {
 			free_rom      = ohci->config_rom;
 			free_rom_bus  = ohci->config_rom_bus;
@@ -2394,7 +2394,7 @@ static int ohci_enable(struct fw_card *card,
 			dma_alloc_coherent(ohci->card.device, CONFIG_ROM_SIZE,
 					   &ohci->next_config_rom_bus,
 					   GFP_KERNEL);
-		if (ohci->next_config_rom == NULL)
+		if (!ohci->next_config_rom)
 			return -ENOMEM;
 
 		copy_config_rom(ohci->next_config_rom, config_rom, length);
@@ -2488,7 +2488,7 @@ static int ohci_set_config_rom(struct fw_card *card,
 	next_config_rom =
 		dma_alloc_coherent(ohci->card.device, CONFIG_ROM_SIZE,
 				   &next_config_rom_bus, GFP_KERNEL);
-	if (next_config_rom == NULL)
+	if (!next_config_rom)
 		return -ENOMEM;
 
 	spin_lock_irq(&ohci->lock);
@@ -2504,7 +2504,7 @@ static int ohci_set_config_rom(struct fw_card *card,
 	 * let this routine free the unused DMA allocation.
 	 */
 
-	if (ohci->next_config_rom == NULL) {
+	if (!ohci->next_config_rom) {
 		ohci->next_config_rom = next_config_rom;
 		ohci->next_config_rom_bus = next_config_rom_bus;
 		next_config_rom = NULL;
@@ -2520,7 +2520,7 @@ static int ohci_set_config_rom(struct fw_card *card,
 	spin_unlock_irq(&ohci->lock);
 
 	/* If we didn't use the DMA allocation, delete it. */
-	if (next_config_rom != NULL)
+	if (next_config_rom)
 		dma_free_coherent(ohci->card.device, CONFIG_ROM_SIZE,
 				  next_config_rom, next_config_rom_bus);
 
@@ -3001,7 +3001,7 @@ static struct fw_iso_context *ohci_allocate_iso_context(struct fw_card *card,
 	memset(ctx, 0, sizeof(*ctx));
 	ctx->header_length = 0;
 	ctx->header = (void *) __get_free_page(GFP_KERNEL);
-	if (ctx->header == NULL) {
+	if (!ctx->header) {
 		ret = -ENOMEM;
 		goto out;
 	}
@@ -3235,7 +3235,7 @@ static int queue_iso_transmit(struct iso_context *ctx,
 	header_z = DIV_ROUND_UP(p->header_length, sizeof(*d));
 
 	d = context_get_descriptors(&ctx->context, z + header_z, &d_bus);
-	if (d == NULL)
+	if (!d)
 		return -ENOMEM;
 
 	if (!p->skip) {
@@ -3333,7 +3333,7 @@ static int queue_iso_packet_per_buffer(struct iso_context *ctx,
 		z = DIV_ROUND_UP(payload_per_buffer + offset, PAGE_SIZE) + 1;
 		d = context_get_descriptors(&ctx->context,
 				z + header_z, &d_bus);
-		if (d == NULL)
+		if (!d)
 			return -ENOMEM;
 
 		d->control      = cpu_to_le16(DESCRIPTOR_STATUS |
@@ -3405,7 +3405,7 @@ static int queue_iso_buffer_fill(struct iso_context *ctx,
 
 	for (i = 0; i < z; i++) {
 		d = context_get_descriptors(&ctx->context, 1, &d_bus);
-		if (d == NULL)
+		if (!d)
 			return -ENOMEM;
 
 		d->control = cpu_to_le16(DESCRIPTOR_INPUT_MORE |
@@ -3572,7 +3572,7 @@ static int pci_probe(struct pci_dev *dev,
 	}
 
 	ohci = kzalloc(sizeof(*ohci), GFP_KERNEL);
-	if (ohci == NULL) {
+	if (!ohci) {
 		err = -ENOMEM;
 		goto fail;
 	}
@@ -3610,7 +3610,7 @@ static int pci_probe(struct pci_dev *dev,
 	}
 
 	ohci->registers = pci_iomap(dev, 0, OHCI1394_REGISTER_SIZE);
-	if (ohci->registers == NULL) {
+	if (!ohci->registers) {
 		ohci_err(ohci, "failed to remap registers\n");
 		err = -ENXIO;
 		goto fail_iomem;
@@ -3686,7 +3686,7 @@ static int pci_probe(struct pci_dev *dev,
 	ohci->it_context_list = kcalloc(ohci->n_it,
 					sizeof(*ohci->it_context_list),
 					GFP_KERNEL);
-	if (ohci->it_context_list == NULL || ohci->ir_context_list == NULL) {
+	if (!ohci->it_context_list || !ohci->ir_context_list) {
 		err = -ENOMEM;
 		goto fail_contexts;
 	}
-- 
2.12.2

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

end of thread, other threads:[~2017-04-20 20:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-20 20:24 [PATCH 0/2] FireWire-OHCI: Fine-tuning for some function implementations SF Markus Elfring
2017-04-20 20:26 ` [PATCH 1/2] firewire: ohci: Use kcalloc() in pci_probe() SF Markus Elfring
2017-04-20 20:28 ` [PATCH 2/2] firewire: ohci: Adjust 15 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).