Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1500842 > unrolled thread

[PATCH 0/5] [media] winbond-cir: Fine-tuning for four function implementations

Started bySF Markus Elfring <elfring@users.sourceforge.net>
First post2016-10-14 13:50 +0200
Last post2016-10-19 16:30 +0200
Articles 20 on this page of 22 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 0/5] [media] winbond-cir: Fine-tuning for four function  implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2016-10-14 13:50 +0200
    [PATCH 2/5] [media] winbond-cir: Move a variable assignment in  wbcir_tx() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-10-14 13:50 +0200
      Re: [PATCH 2/5] [media] winbond-cir: Move a variable assignment  in wbcir_tx() "David Härdeman" <david@hardeman.nu> - 2016-10-19 17:40 +0200
        Re: [media] winbond-cir: Move a variable assignment in wbcir_tx() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-10-19 18:30 +0200
    [PATCH 5/5] [media] winbond-cir: Move a variable assignment in two  functions SF Markus Elfring <elfring@users.sourceforge.net> - 2016-10-14 13:50 +0200
      Re: [PATCH 5/5] [media] winbond-cir: Move a variable assignment  in two functions "David Härdeman" <david@hardeman.nu> - 2016-10-19 16:30 +0200
    [PATCH 4/5] [media] winbond-cir: One variable and its check less in  wbcir_shutdown() after error detection SF Markus Elfring <elfring@users.sourceforge.net> - 2016-10-14 13:50 +0200
      Re: [PATCH 4/5] [media] winbond-cir: One variable and its check less  in wbcir_shutdown() after error detection Sean Young <sean@mess.org> - 2016-10-15 15:40 +0200
        Re: [PATCH 4/5] [media] winbond-cir: One variable and its check less  in wbcir_shutdown() after error detection SF Markus Elfring <elfring@users.sourceforge.net> - 2016-10-15 18:50 +0200
          Re: [PATCH 4/5] [media] winbond-cir: One variable and its check  less in wbcir_shutdown() after error detection "David Härdeman" <david@hardeman.nu> - 2016-10-19 16:30 +0200
            Re: [PATCH 4/5] [media] winbond-cir: One variable and its check less  in wbcir_shutdown() after error detection SF Markus Elfring <elfring@users.sourceforge.net> - 2016-10-19 18:30 +0200
        Re: [PATCH 4/5] [media] winbond-cir: One variable and its check  less in wbcir_shutdown() after error detection "David Härdeman" <david@hardeman.nu> - 2016-10-19 16:30 +0200
    [PATCH 1/5] [media] winbond-cir: Use kmalloc_array() in wbcir_tx() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-10-14 13:50 +0200
      Re: [PATCH 1/5] [media] winbond-cir: Use kmalloc_array() in  wbcir_tx() "David Härdeman" <david@hardeman.nu> - 2016-10-19 17:40 +0200
    [PATCH 3/5] [media] winbond-cir: Move assignments for three variables  in wbcir_shutdown() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-10-14 13:50 +0200
      Re: [PATCH 3/5] [media] winbond-cir: Move assignments for three  variables in wbcir_shutdown() "David Härdeman" <david@hardeman.nu> - 2016-10-19 16:30 +0200
        Re: [media] winbond-cir: Move assignments for three variables in  wbcir_shutdown() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-10-19 16:30 +0200
          Re: [media] winbond-cir: Move assignments for three variables in  wbcir_shutdown() "David Härdeman" <david@hardeman.nu> - 2016-10-19 17:50 +0200
    Re: [media] winbond-cir: Move a variable assignment in two functions SF Markus Elfring <elfring@users.sourceforge.net> - 2016-10-19 16:20 +0200
    Re: [media] winbond-cir: Move a variable assignment in wbcir_tx() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-10-19 16:20 +0200
    Re: [media] winbond-cir: Move assignments for three variables in  wbcir_shutdown() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-10-19 16:20 +0200
    Re: [media] winbond-cir: Move a variable assignment in wbcir_tx() "David Härdeman" <david@hardeman.nu> - 2016-10-19 16:30 +0200

Page 1 of 2  [1] 2  Next page →


#1500842 — [PATCH 0/5] [media] winbond-cir: Fine-tuning for four function implementations

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2016-10-14 13:50 +0200
Subject[PATCH 0/5] [media] winbond-cir: Fine-tuning for four function implementations
Message-ID<ss99T-JJ-1@gated-at.bofh.it>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 14 Oct 2016 13:24:35 +0200

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

Markus Elfring (5):
  Use kmalloc_array() in wbcir_tx()
  Move a variable assignment in wbcir_tx()
  Move assignments for three variables in wbcir_shutdown()
  One variable and its check less in wbcir_shutdown() after error detection
  Move a variable assignment in two functions

 drivers/media/rc/winbond-cir.c | 95 +++++++++++++++++++-----------------------
 1 file changed, 44 insertions(+), 51 deletions(-)

-- 
2.10.1

[toc] | [next] | [standalone]


#1500849 — [PATCH 2/5] [media] winbond-cir: Move a variable assignment in wbcir_tx()

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2016-10-14 13:50 +0200
Subject[PATCH 2/5] [media] winbond-cir: Move a variable assignment in wbcir_tx()
Message-ID<ss99U-JJ-29@gated-at.bofh.it>
In reply to#1500842
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 14 Oct 2016 07:34:46 +0200

Move the assignment for the local variable "data" behind the source code
for a memory allocation by this function.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/media/rc/winbond-cir.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
index 59050f5..fd997f0 100644
--- a/drivers/media/rc/winbond-cir.c
+++ b/drivers/media/rc/winbond-cir.c
@@ -655,7 +655,7 @@ wbcir_txmask(struct rc_dev *dev, u32 mask)
 static int
 wbcir_tx(struct rc_dev *dev, unsigned *b, unsigned count)
 {
-	struct wbcir_data *data = dev->priv;
+	struct wbcir_data *data;
 	unsigned *buf;
 	unsigned i;
 	unsigned long flags;
@@ -668,6 +668,7 @@ wbcir_tx(struct rc_dev *dev, unsigned *b, unsigned count)
 	for (i = 0; i < count; i++)
 		buf[i] = DIV_ROUND_CLOSEST(b[i], 10);
 
+	data = dev->priv;
 	/* Not sure if this is possible, but better safe than sorry */
 	spin_lock_irqsave(&data->spinlock, flags);
 	if (data->txstate != WBCIR_TXSTATE_INACTIVE) {
-- 
2.10.1

[toc] | [prev] | [next] | [standalone]


#1503930 — Re: [PATCH 2/5] [media] winbond-cir: Move a variable assignment in wbcir_tx()

From"David Härdeman" <david@hardeman.nu>
Date2016-10-19 17:40 +0200
SubjectRe: [PATCH 2/5] [media] winbond-cir: Move a variable assignment in wbcir_tx()
Message-ID<stZSQ-2nd-141@gated-at.bofh.it>
In reply to#1500849
October 14, 2016 1:42 PM, "SF Markus Elfring" <elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 14 Oct 2016 07:34:46 +0200
> 
> Move the assignment for the local variable "data" behind the source code
> for a memory allocation by this function.

Sorry, I can't see what the point is?


> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> drivers/media/rc/winbond-cir.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
> index 59050f5..fd997f0 100644
> --- a/drivers/media/rc/winbond-cir.c
> +++ b/drivers/media/rc/winbond-cir.c
> @@ -655,7 +655,7 @@ wbcir_txmask(struct rc_dev *dev, u32 mask)
> static int
> wbcir_tx(struct rc_dev *dev, unsigned *b, unsigned count)
> {
> - struct wbcir_data *data = dev->priv;
> + struct wbcir_data *data;
> unsigned *buf;
> unsigned i;
> unsigned long flags;
> @@ -668,6 +668,7 @@ wbcir_tx(struct rc_dev *dev, unsigned *b, unsigned count)
> for (i = 0; i < count; i++)
> buf[i] = DIV_ROUND_CLOSEST(b[i], 10);
> 
> + data = dev->priv;
> /* Not sure if this is possible, but better safe than sorry */
> spin_lock_irqsave(&data->spinlock, flags);
> if (data->txstate != WBCIR_TXSTATE_INACTIVE) {
> -- 
> 2.10.1

[toc] | [prev] | [next] | [standalone]


#1504092 — Re: [media] winbond-cir: Move a variable assignment in wbcir_tx()

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2016-10-19 18:30 +0200
SubjectRe: [media] winbond-cir: Move a variable assignment in wbcir_tx()
Message-ID<stZSQ-2nd-139@gated-at.bofh.it>
In reply to#1503930
>> Move the assignment for the local variable "data" behind the source code
>> for a memory allocation by this function.
> 
> Sorry, I can't see what the point is?

* How do you think about to avoid a variable assignment in case
  that this memory allocation failed anyhow?

* Do you care for data access locality?

Regards,
Markus

[toc] | [prev] | [next] | [standalone]


#1500850 — [PATCH 5/5] [media] winbond-cir: Move a variable assignment in two functions

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2016-10-14 13:50 +0200
Subject[PATCH 5/5] [media] winbond-cir: Move a variable assignment in two functions
Message-ID<ss99U-JJ-31@gated-at.bofh.it>
In reply to#1500842
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 14 Oct 2016 13:13:11 +0200

Move the assignment for the local variable "data" behind the source code
for condition checks by these functions.

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

diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
index 3d286b9..716b1fe 100644
--- a/drivers/media/rc/winbond-cir.c
+++ b/drivers/media/rc/winbond-cir.c
@@ -566,7 +566,7 @@ wbcir_set_carrier_report(struct rc_dev *dev, int enable)
 static int
 wbcir_txcarrier(struct rc_dev *dev, u32 carrier)
 {
-	struct wbcir_data *data = dev->priv;
+	struct wbcir_data *data;
 	unsigned long flags;
 	u8 val;
 	u32 freq;
@@ -592,6 +592,7 @@ wbcir_txcarrier(struct rc_dev *dev, u32 carrier)
 		break;
 	}
 
+	data = dev->priv;
 	spin_lock_irqsave(&data->spinlock, flags);
 	if (data->txstate != WBCIR_TXSTATE_INACTIVE) {
 		spin_unlock_irqrestore(&data->spinlock, flags);
@@ -611,7 +612,7 @@ wbcir_txcarrier(struct rc_dev *dev, u32 carrier)
 static int
 wbcir_txmask(struct rc_dev *dev, u32 mask)
 {
-	struct wbcir_data *data = dev->priv;
+	struct wbcir_data *data;
 	unsigned long flags;
 	u8 val;
 
@@ -637,6 +638,7 @@ wbcir_txmask(struct rc_dev *dev, u32 mask)
 		return -EINVAL;
 	}
 
+	data = dev->priv;
 	spin_lock_irqsave(&data->spinlock, flags);
 	if (data->txstate != WBCIR_TXSTATE_INACTIVE) {
 		spin_unlock_irqrestore(&data->spinlock, flags);
-- 
2.10.1

[toc] | [prev] | [next] | [standalone]


#1503672 — Re: [PATCH 5/5] [media] winbond-cir: Move a variable assignment in two functions

From"David Härdeman" <david@hardeman.nu>
Date2016-10-19 16:30 +0200
SubjectRe: [PATCH 5/5] [media] winbond-cir: Move a variable assignment in two functions
Message-ID<stZSP-2nd-119@gated-at.bofh.it>
In reply to#1500850
October 14, 2016 1:45 PM, "SF Markus Elfring" <elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 14 Oct 2016 13:13:11 +0200
> 
> Move the assignment for the local variable "data" behind the source code
> for condition checks by these functions.

Why?

> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> drivers/media/rc/winbond-cir.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
> index 3d286b9..716b1fe 100644
> --- a/drivers/media/rc/winbond-cir.c
> +++ b/drivers/media/rc/winbond-cir.c
> @@ -566,7 +566,7 @@ wbcir_set_carrier_report(struct rc_dev *dev, int enable)
> static int
> wbcir_txcarrier(struct rc_dev *dev, u32 carrier)
> {
> - struct wbcir_data *data = dev->priv;
> + struct wbcir_data *data;
> unsigned long flags;
> u8 val;
> u32 freq;
> @@ -592,6 +592,7 @@ wbcir_txcarrier(struct rc_dev *dev, u32 carrier)
> break;
> }
> 
> + data = dev->priv;
> spin_lock_irqsave(&data->spinlock, flags);
> if (data->txstate != WBCIR_TXSTATE_INACTIVE) {
> spin_unlock_irqrestore(&data->spinlock, flags);
> @@ -611,7 +612,7 @@ wbcir_txcarrier(struct rc_dev *dev, u32 carrier)
> static int
> wbcir_txmask(struct rc_dev *dev, u32 mask)
> {
> - struct wbcir_data *data = dev->priv;
> + struct wbcir_data *data;
> unsigned long flags;
> u8 val;
> 
> @@ -637,6 +638,7 @@ wbcir_txmask(struct rc_dev *dev, u32 mask)
> return -EINVAL;
> }
> 
> + data = dev->priv;
> spin_lock_irqsave(&data->spinlock, flags);
> if (data->txstate != WBCIR_TXSTATE_INACTIVE) {
> spin_unlock_irqrestore(&data->spinlock, flags);
> -- 
> 2.10.1

[toc] | [prev] | [next] | [standalone]


#1500851 — [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2016-10-14 13:50 +0200
Subject[PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection
Message-ID<ss99U-JJ-33@gated-at.bofh.it>
In reply to#1500842
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 14 Oct 2016 12:48:41 +0200

The local variable "do_wake" was set to "false" after an invalid system
setting was detected so that a bit of error handling was triggered.

* Replace these assignments by direct jumps to the source code with the
desired exception handling.

* Delete this status variable and a corresponding check which became
  unnecessary with this refactoring.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/media/rc/winbond-cir.c | 78 ++++++++++++++++++------------------------
 1 file changed, 34 insertions(+), 44 deletions(-)

diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
index 9d05e17..3d286b9 100644
--- a/drivers/media/rc/winbond-cir.c
+++ b/drivers/media/rc/winbond-cir.c
@@ -699,16 +699,13 @@ wbcir_shutdown(struct pnp_dev *device)
 {
 	struct device *dev = &device->dev;
 	struct wbcir_data *data = pnp_get_drvdata(device);
-	bool do_wake = true;
 	u8 match[11];
 	u8 mask[11];
 	u8 rc6_csl;
 	int i;
 
-	if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev)) {
-		do_wake = false;
-		goto finish;
-	}
+	if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev))
+		goto clear_bits;
 
 	rc6_csl = 0;
 	memset(match, 0, sizeof(match));
@@ -716,9 +713,8 @@ wbcir_shutdown(struct pnp_dev *device)
 	switch (protocol) {
 	case IR_PROTOCOL_RC5:
 		if (wake_sc > 0xFFF) {
-			do_wake = false;
 			dev_err(dev, "RC5 - Invalid wake scancode\n");
-			break;
+			goto clear_bits;
 		}
 
 		/* Mask = 13 bits, ex toggle */
@@ -735,9 +731,8 @@ wbcir_shutdown(struct pnp_dev *device)
 
 	case IR_PROTOCOL_NEC:
 		if (wake_sc > 0xFFFFFF) {
-			do_wake = false;
 			dev_err(dev, "NEC - Invalid wake scancode\n");
-			break;
+			goto clear_bits;
 		}
 
 		mask[0] = mask[1] = mask[2] = mask[3] = 0xFF;
@@ -757,9 +752,8 @@ wbcir_shutdown(struct pnp_dev *device)
 
 		if (wake_rc6mode == 0) {
 			if (wake_sc > 0xFFFF) {
-				do_wake = false;
 				dev_err(dev, "RC6 - Invalid wake scancode\n");
-				break;
+				goto clear_bits;
 			}
 
 			/* Command */
@@ -813,9 +807,8 @@ wbcir_shutdown(struct pnp_dev *device)
 			} else if (wake_sc <= 0x007FFFFF) {
 				rc6_csl = 60;
 			} else {
-				do_wake = false;
 				dev_err(dev, "RC6 - Invalid wake scancode\n");
-				break;
+				goto clear_bits;
 			}
 
 			/* Header */
@@ -825,49 +818,38 @@ wbcir_shutdown(struct pnp_dev *device)
 			mask[i++] = 0x0F;
 
 		} else {
-			do_wake = false;
 			dev_err(dev, "RC6 - Invalid wake mode\n");
+			goto clear_bits;
 		}
 
 		break;
 
 	default:
-		do_wake = false;
-		break;
+		goto clear_bits;
 	}
 
-finish:
-	if (do_wake) {
-		/* Set compare and compare mask */
-		wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
-			       WBCIR_REGSEL_COMPARE | WBCIR_REG_ADDR0,
-			       0x3F);
-		outsb(data->wbase + WBCIR_REG_WCEIR_DATA, match, 11);
-		wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
-			       WBCIR_REGSEL_MASK | WBCIR_REG_ADDR0,
-			       0x3F);
-		outsb(data->wbase + WBCIR_REG_WCEIR_DATA, mask, 11);
-
-		/* RC6 Compare String Len */
-		outb(rc6_csl, data->wbase + WBCIR_REG_WCEIR_CSL);
-
-		/* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */
-		wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17);
+	/* Set compare and compare mask */
+	wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
+		       WBCIR_REGSEL_COMPARE | WBCIR_REG_ADDR0,
+		       0x3F);
+	outsb(data->wbase + WBCIR_REG_WCEIR_DATA, match, 11);
+	wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
+		       WBCIR_REGSEL_MASK | WBCIR_REG_ADDR0,
+		       0x3F);
+	outsb(data->wbase + WBCIR_REG_WCEIR_DATA, mask, 11);
 
-		/* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */
-		wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x01, 0x07);
+	/* RC6 Compare String Len */
+	outb(rc6_csl, data->wbase + WBCIR_REG_WCEIR_CSL);
 
-		/* Set CEIR_EN */
-		wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01);
-
-	} else {
-		/* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
-		wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
+	/* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */
+	wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17);
 
-		/* Clear CEIR_EN */
-		wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
-	}
+	/* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */
+	wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x01, 0x07);
 
+	/* Set CEIR_EN */
+	wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01);
+set_irqmask:
 	/*
 	 * ACPI will set the HW disable bit for SP3 which means that the
 	 * output signals are left in an undefined state which may cause
@@ -876,6 +858,14 @@ wbcir_shutdown(struct pnp_dev *device)
 	 */
 	wbcir_set_irqmask(data, WBCIR_IRQ_NONE);
 	disable_irq(data->irq);
+	return;
+clear_bits:
+	/* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
+	wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
+
+	/* Clear CEIR_EN */
+	wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
+	goto set_irqmask;
 }
 
 static int
-- 
2.10.1

[toc] | [prev] | [next] | [standalone]


#1501292 — Re: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection

FromSean Young <sean@mess.org>
Date2016-10-15 15:40 +0200
SubjectRe: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection
Message-ID<ssxlT-8f4-3@gated-at.bofh.it>
In reply to#1500851
On Fri, Oct 14, 2016 at 01:44:02PM +0200, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 14 Oct 2016 12:48:41 +0200
> 
> The local variable "do_wake" was set to "false" after an invalid system
> setting was detected so that a bit of error handling was triggered.
> 
> * Replace these assignments by direct jumps to the source code with the
> desired exception handling.
> 
> * Delete this status variable and a corresponding check which became
>   unnecessary with this refactoring.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  drivers/media/rc/winbond-cir.c | 78 ++++++++++++++++++------------------------
>  1 file changed, 34 insertions(+), 44 deletions(-)
> 
> diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
> index 9d05e17..3d286b9 100644
> --- a/drivers/media/rc/winbond-cir.c
> +++ b/drivers/media/rc/winbond-cir.c
> @@ -699,16 +699,13 @@ wbcir_shutdown(struct pnp_dev *device)
>  {
>  	struct device *dev = &device->dev;
>  	struct wbcir_data *data = pnp_get_drvdata(device);
> -	bool do_wake = true;
>  	u8 match[11];
>  	u8 mask[11];
>  	u8 rc6_csl;
>  	int i;
>  
> -	if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev)) {
> -		do_wake = false;
> -		goto finish;
> -	}
> +	if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev))
> +		goto clear_bits;
>  
>  	rc6_csl = 0;
>  	memset(match, 0, sizeof(match));
> @@ -716,9 +713,8 @@ wbcir_shutdown(struct pnp_dev *device)
>  	switch (protocol) {
>  	case IR_PROTOCOL_RC5:
>  		if (wake_sc > 0xFFF) {
> -			do_wake = false;
>  			dev_err(dev, "RC5 - Invalid wake scancode\n");
> -			break;
> +			goto clear_bits;
>  		}
>  
>  		/* Mask = 13 bits, ex toggle */
> @@ -735,9 +731,8 @@ wbcir_shutdown(struct pnp_dev *device)
>  
>  	case IR_PROTOCOL_NEC:
>  		if (wake_sc > 0xFFFFFF) {
> -			do_wake = false;
>  			dev_err(dev, "NEC - Invalid wake scancode\n");
> -			break;
> +			goto clear_bits;
>  		}
>  
>  		mask[0] = mask[1] = mask[2] = mask[3] = 0xFF;
> @@ -757,9 +752,8 @@ wbcir_shutdown(struct pnp_dev *device)
>  
>  		if (wake_rc6mode == 0) {
>  			if (wake_sc > 0xFFFF) {
> -				do_wake = false;
>  				dev_err(dev, "RC6 - Invalid wake scancode\n");
> -				break;
> +				goto clear_bits;
>  			}
>  
>  			/* Command */
> @@ -813,9 +807,8 @@ wbcir_shutdown(struct pnp_dev *device)
>  			} else if (wake_sc <= 0x007FFFFF) {
>  				rc6_csl = 60;
>  			} else {
> -				do_wake = false;
>  				dev_err(dev, "RC6 - Invalid wake scancode\n");
> -				break;
> +				goto clear_bits;
>  			}
>  
>  			/* Header */
> @@ -825,49 +818,38 @@ wbcir_shutdown(struct pnp_dev *device)
>  			mask[i++] = 0x0F;
>  
>  		} else {
> -			do_wake = false;
>  			dev_err(dev, "RC6 - Invalid wake mode\n");
> +			goto clear_bits;
>  		}
>  
>  		break;
>  
>  	default:
> -		do_wake = false;
> -		break;
> +		goto clear_bits;
>  	}
>  
> -finish:
> -	if (do_wake) {
> -		/* Set compare and compare mask */
> -		wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
> -			       WBCIR_REGSEL_COMPARE | WBCIR_REG_ADDR0,
> -			       0x3F);
> -		outsb(data->wbase + WBCIR_REG_WCEIR_DATA, match, 11);
> -		wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
> -			       WBCIR_REGSEL_MASK | WBCIR_REG_ADDR0,
> -			       0x3F);
> -		outsb(data->wbase + WBCIR_REG_WCEIR_DATA, mask, 11);
> -
> -		/* RC6 Compare String Len */
> -		outb(rc6_csl, data->wbase + WBCIR_REG_WCEIR_CSL);
> -
> -		/* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */
> -		wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17);
> +	/* Set compare and compare mask */
> +	wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
> +		       WBCIR_REGSEL_COMPARE | WBCIR_REG_ADDR0,
> +		       0x3F);
> +	outsb(data->wbase + WBCIR_REG_WCEIR_DATA, match, 11);
> +	wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
> +		       WBCIR_REGSEL_MASK | WBCIR_REG_ADDR0,
> +		       0x3F);
> +	outsb(data->wbase + WBCIR_REG_WCEIR_DATA, mask, 11);
>  
> -		/* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */
> -		wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x01, 0x07);
> +	/* RC6 Compare String Len */
> +	outb(rc6_csl, data->wbase + WBCIR_REG_WCEIR_CSL);
>  
> -		/* Set CEIR_EN */
> -		wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01);
> -
> -	} else {
> -		/* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
> -		wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
> +	/* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */
> +	wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17);
>  
> -		/* Clear CEIR_EN */
> -		wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
> -	}
> +	/* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */
> +	wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x01, 0x07);
>  
> +	/* Set CEIR_EN */
> +	wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01);
> +set_irqmask:
>  	/*
>  	 * ACPI will set the HW disable bit for SP3 which means that the
>  	 * output signals are left in an undefined state which may cause
> @@ -876,6 +858,14 @@ wbcir_shutdown(struct pnp_dev *device)
>  	 */
>  	wbcir_set_irqmask(data, WBCIR_IRQ_NONE);
>  	disable_irq(data->irq);
> +	return;
> +clear_bits:
> +	/* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
> +	wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
> +
> +	/* Clear CEIR_EN */
> +	wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
> +	goto set_irqmask;

I'm not convinced that adding a goto which goes backwards is making this
code any more readible, just so that a local variable can be dropped.


Sean

>  }
>  
>  static int
> -- 
> 2.10.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

[toc] | [prev] | [next] | [standalone]


#1501321 — Re: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2016-10-15 18:50 +0200
SubjectRe: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection
Message-ID<ssAjL-1Lv-1@gated-at.bofh.it>
In reply to#1501292
>> +	/* Set CEIR_EN */
>> +	wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01);
>> +set_irqmask:
>>  	/*
>>  	 * ACPI will set the HW disable bit for SP3 which means that the
>>  	 * output signals are left in an undefined state which may cause
>> @@ -876,6 +858,14 @@ wbcir_shutdown(struct pnp_dev *device)
>>  	 */
>>  	wbcir_set_irqmask(data, WBCIR_IRQ_NONE);
>>  	disable_irq(data->irq);
>> +	return;
>> +clear_bits:
>> +	/* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
>> +	wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
>> +
>> +	/* Clear CEIR_EN */
>> +	wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
>> +	goto set_irqmask;
> 
> I'm not convinced that adding a goto which goes backwards is making this
> code any more readible, just so that a local variable can be dropped.

Thanks for your feedback.

Is such a "backward jump" usual and finally required when you would like
to move a bit of common error handling code to the end without using extra
local variables and a few statements should still be performed after it?

Regards,
Markus

[toc] | [prev] | [next] | [standalone]


#1503677 — Re: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection

From"David Härdeman" <david@hardeman.nu>
Date2016-10-19 16:30 +0200
SubjectRe: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection
Message-ID<su02v-2rf-107@gated-at.bofh.it>
In reply to#1501321
October 15, 2016 6:42 PM, "SF Markus Elfring" <elfring@users.sourceforge.net> wrote:
>>> + /* Set CEIR_EN */
>>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01);
>>> +set_irqmask:
>>> /*
>>> * ACPI will set the HW disable bit for SP3 which means that the
>>> * output signals are left in an undefined state which may cause
>>> @@ -876,6 +858,14 @@ wbcir_shutdown(struct pnp_dev *device)
>>> */
>>> wbcir_set_irqmask(data, WBCIR_IRQ_NONE);
>>> disable_irq(data->irq);
>>> + return;
>>> +clear_bits:
>>> + /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
>>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
>>> +
>>> + /* Clear CEIR_EN */
>>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
>>> + goto set_irqmask;
>> 
>> I'm not convinced that adding a goto which goes backwards is making this
>> code any more readible, just so that a local variable can be dropped.
> 
> Thanks for your feedback.
> 
> Is such a "backward jump" usual and finally required when you would like
> to move a bit of common error handling code to the end without using extra
> local variables and a few statements should still be performed after it?
> 

I'm sorry, I can't parse this.

[toc] | [prev] | [next] | [standalone]


#1504079 — Re: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2016-10-19 18:30 +0200
SubjectRe: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection
Message-ID<su1UB-3KZ-7@gated-at.bofh.it>
In reply to#1503677
>>>> + /* Set CEIR_EN */
>>>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01);
>>>> +set_irqmask:
>>>> /*
>>>> * ACPI will set the HW disable bit for SP3 which means that the
>>>> * output signals are left in an undefined state which may cause
>>>> @@ -876,6 +858,14 @@ wbcir_shutdown(struct pnp_dev *device)
>>>> */
>>>> wbcir_set_irqmask(data, WBCIR_IRQ_NONE);
>>>> disable_irq(data->irq);
>>>> + return;
>>>> +clear_bits:
>>>> + /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
>>>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
>>>> +
>>>> + /* Clear CEIR_EN */
>>>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
>>>> + goto set_irqmask;
>>>
>>> I'm not convinced that adding a goto which goes backwards is making this
>>> code any more readible, just so that a local variable can be dropped.
>>
>> Thanks for your feedback.
>>
>> Is such a "backward jump" usual and finally required when you would like
>> to move a bit of common error handling code to the end without using extra
>> local variables and a few statements should still be performed after it?
>>
> 
> I'm sorry, I can't parse this.

Can an other update suggestion like "[PATCH 6/6] crypto-caamhash:
Move common error handling code in two functions" explain this technique
a bit better in principle?
https://patchwork.kernel.org/patch/9333861/
https://lkml.kernel.org/r/<baa5db91-27e7-ecab-f2c9-29e549b6e5f0@users.sourceforge.net>

Regards,
Markus

[toc] | [prev] | [next] | [standalone]


#1503656 — Re: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection

From"David Härdeman" <david@hardeman.nu>
Date2016-10-19 16:30 +0200
SubjectRe: [PATCH 4/5] [media] winbond-cir: One variable and its check less in wbcir_shutdown() after error detection
Message-ID<su02t-2rf-33@gated-at.bofh.it>
In reply to#1501292
October 15, 2016 3:30 PM, "Sean Young" <sean@mess.org> wrote:
> On Fri, Oct 14, 2016 at 01:44:02PM +0200, SF Markus Elfring wrote:
> 
>> From: Markus Elfring <elfring@users.sourceforge.net>
>> Date: Fri, 14 Oct 2016 12:48:41 +0200
>> 
>> The local variable "do_wake" was set to "false" after an invalid system
>> setting was detected so that a bit of error handling was triggered.
>> 
>> * Replace these assignments by direct jumps to the source code with the
>> desired exception handling.
>> 
>> * Delete this status variable and a corresponding check which became
>> unnecessary with this refactoring.
>> 
>> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
>> ---
>> drivers/media/rc/winbond-cir.c | 78 ++++++++++++++++++------------------------
>> 1 file changed, 34 insertions(+), 44 deletions(-)
>> 
>> diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
>> index 9d05e17..3d286b9 100644
>> --- a/drivers/media/rc/winbond-cir.c
>> +++ b/drivers/media/rc/winbond-cir.c
>> @@ -699,16 +699,13 @@ wbcir_shutdown(struct pnp_dev *device)
>> {
>> struct device *dev = &device->dev;
>> struct wbcir_data *data = pnp_get_drvdata(device);
>> - bool do_wake = true;
>> u8 match[11];
>> u8 mask[11];
>> u8 rc6_csl;
>> int i;
>> 
>> - if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev)) {
>> - do_wake = false;
>> - goto finish;
>> - }
>> + if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev))
>> + goto clear_bits;
>> 
>> rc6_csl = 0;
>> memset(match, 0, sizeof(match));
>> @@ -716,9 +713,8 @@ wbcir_shutdown(struct pnp_dev *device)
>> switch (protocol) {
>> case IR_PROTOCOL_RC5:
>> if (wake_sc > 0xFFF) {
>> - do_wake = false;
>> dev_err(dev, "RC5 - Invalid wake scancode\n");
>> - break;
>> + goto clear_bits;
>> }
>> 
>> /* Mask = 13 bits, ex toggle */
>> @@ -735,9 +731,8 @@ wbcir_shutdown(struct pnp_dev *device)
>> 
>> case IR_PROTOCOL_NEC:
>> if (wake_sc > 0xFFFFFF) {
>> - do_wake = false;
>> dev_err(dev, "NEC - Invalid wake scancode\n");
>> - break;
>> + goto clear_bits;
>> }
>> 
>> mask[0] = mask[1] = mask[2] = mask[3] = 0xFF;
>> @@ -757,9 +752,8 @@ wbcir_shutdown(struct pnp_dev *device)
>> 
>> if (wake_rc6mode == 0) {
>> if (wake_sc > 0xFFFF) {
>> - do_wake = false;
>> dev_err(dev, "RC6 - Invalid wake scancode\n");
>> - break;
>> + goto clear_bits;
>> }
>> 
>> /* Command */
>> @@ -813,9 +807,8 @@ wbcir_shutdown(struct pnp_dev *device)
>> } else if (wake_sc <= 0x007FFFFF) {
>> rc6_csl = 60;
>> } else {
>> - do_wake = false;
>> dev_err(dev, "RC6 - Invalid wake scancode\n");
>> - break;
>> + goto clear_bits;
>> }
>> 
>> /* Header */
>> @@ -825,49 +818,38 @@ wbcir_shutdown(struct pnp_dev *device)
>> mask[i++] = 0x0F;
>> 
>> } else {
>> - do_wake = false;
>> dev_err(dev, "RC6 - Invalid wake mode\n");
>> + goto clear_bits;
>> }
>> 
>> break;
>> 
>> default:
>> - do_wake = false;
>> - break;
>> + goto clear_bits;
>> }
>> 
>> -finish:
>> - if (do_wake) {
>> - /* Set compare and compare mask */
>> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
>> - WBCIR_REGSEL_COMPARE | WBCIR_REG_ADDR0,
>> - 0x3F);
>> - outsb(data->wbase + WBCIR_REG_WCEIR_DATA, match, 11);
>> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
>> - WBCIR_REGSEL_MASK | WBCIR_REG_ADDR0,
>> - 0x3F);
>> - outsb(data->wbase + WBCIR_REG_WCEIR_DATA, mask, 11);
>> -
>> - /* RC6 Compare String Len */
>> - outb(rc6_csl, data->wbase + WBCIR_REG_WCEIR_CSL);
>> -
>> - /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */
>> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17);
>> + /* Set compare and compare mask */
>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
>> + WBCIR_REGSEL_COMPARE | WBCIR_REG_ADDR0,
>> + 0x3F);
>> + outsb(data->wbase + WBCIR_REG_WCEIR_DATA, match, 11);
>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_INDEX,
>> + WBCIR_REGSEL_MASK | WBCIR_REG_ADDR0,
>> + 0x3F);
>> + outsb(data->wbase + WBCIR_REG_WCEIR_DATA, mask, 11);
>> 
>> - /* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */
>> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x01, 0x07);
>> + /* RC6 Compare String Len */
>> + outb(rc6_csl, data->wbase + WBCIR_REG_WCEIR_CSL);
>> 
>> - /* Set CEIR_EN */
>> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01);
>> -
>> - } else {
>> - /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
>> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
>> + /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */
>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_STS, 0x17, 0x17);
>> 
>> - /* Clear CEIR_EN */
>> - wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
>> - }
>> + /* Clear BUFF_EN, Clear END_EN, Set MATCH_EN */
>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x01, 0x07);
>> 
>> + /* Set CEIR_EN */
>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x01, 0x01);
>> +set_irqmask:
>> /*
>> * ACPI will set the HW disable bit for SP3 which means that the
>> * output signals are left in an undefined state which may cause
>> @@ -876,6 +858,14 @@ wbcir_shutdown(struct pnp_dev *device)
>> */
>> wbcir_set_irqmask(data, WBCIR_IRQ_NONE);
>> disable_irq(data->irq);
>> + return;
>> +clear_bits:
>> + /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
>> +
>> + /* Clear CEIR_EN */
>> + wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
>> + goto set_irqmask;
> 
> I'm not convinced that adding a goto which goes backwards is making this
> code any more readible, just so that a local variable can be dropped.
> 

Agreed.

[toc] | [prev] | [next] | [standalone]


#1500856 — [PATCH 1/5] [media] winbond-cir: Use kmalloc_array() in wbcir_tx()

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2016-10-14 13:50 +0200
Subject[PATCH 1/5] [media] winbond-cir: Use kmalloc_array() in wbcir_tx()
Message-ID<ss99U-JJ-39@gated-at.bofh.it>
In reply to#1500842
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 14 Oct 2016 07:19:00 +0200

A multiplication for the size determination of a memory allocation
indicated that an array data structure should be processed.
Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/media/rc/winbond-cir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
index 95ae60e..59050f5 100644
--- a/drivers/media/rc/winbond-cir.c
+++ b/drivers/media/rc/winbond-cir.c
@@ -660,7 +660,7 @@ wbcir_tx(struct rc_dev *dev, unsigned *b, unsigned count)
 	unsigned i;
 	unsigned long flags;
 
-	buf = kmalloc(count * sizeof(*b), GFP_KERNEL);
+	buf = kmalloc_array(count, sizeof(*b), GFP_KERNEL);
 	if (!buf)
 		return -ENOMEM;
 
-- 
2.10.1

[toc] | [prev] | [next] | [standalone]


#1503926 — Re: [PATCH 1/5] [media] winbond-cir: Use kmalloc_array() in wbcir_tx()

From"David Härdeman" <david@hardeman.nu>
Date2016-10-19 17:40 +0200
SubjectRe: [PATCH 1/5] [media] winbond-cir: Use kmalloc_array() in wbcir_tx()
Message-ID<su18d-37s-11@gated-at.bofh.it>
In reply to#1500856
October 14, 2016 1:41 PM, "SF Markus Elfring" <elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 14 Oct 2016 07:19:00 +0200
> 
> A multiplication for the size determination of a memory allocation
> indicated that an array data structure should be processed.
> Thus use the corresponding function "kmalloc_array".
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>

Sure...why not...

Signed-off-by: David Härdeman <david@hardeman.nu>


> ---
> drivers/media/rc/winbond-cir.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
> index 95ae60e..59050f5 100644
> --- a/drivers/media/rc/winbond-cir.c
> +++ b/drivers/media/rc/winbond-cir.c
> @@ -660,7 +660,7 @@ wbcir_tx(struct rc_dev *dev, unsigned *b, unsigned count)
> unsigned i;
> unsigned long flags;
> 
> - buf = kmalloc(count * sizeof(*b), GFP_KERNEL);
> + buf = kmalloc_array(count, sizeof(*b), GFP_KERNEL);
> if (!buf)
> return -ENOMEM;
> 
> -- 
> 2.10.1

[toc] | [prev] | [next] | [standalone]


#1500864 — [PATCH 3/5] [media] winbond-cir: Move assignments for three variables in wbcir_shutdown()

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2016-10-14 13:50 +0200
Subject[PATCH 3/5] [media] winbond-cir: Move assignments for three variables in wbcir_shutdown()
Message-ID<ss99V-JJ-65@gated-at.bofh.it>
In reply to#1500842
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 14 Oct 2016 10:40:12 +0200

Move the setting for the local variables "mask", "match" and "rc6_csl"
behind the source code for a condition check by this function
at the beginning.

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

diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
index fd997f0..9d05e17 100644
--- a/drivers/media/rc/winbond-cir.c
+++ b/drivers/media/rc/winbond-cir.c
@@ -702,17 +702,17 @@ wbcir_shutdown(struct pnp_dev *device)
 	bool do_wake = true;
 	u8 match[11];
 	u8 mask[11];
-	u8 rc6_csl = 0;
+	u8 rc6_csl;
 	int i;
 
-	memset(match, 0, sizeof(match));
-	memset(mask, 0, sizeof(mask));
-
 	if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev)) {
 		do_wake = false;
 		goto finish;
 	}
 
+	rc6_csl = 0;
+	memset(match, 0, sizeof(match));
+	memset(mask, 0, sizeof(mask));
 	switch (protocol) {
 	case IR_PROTOCOL_RC5:
 		if (wake_sc > 0xFFF) {
-- 
2.10.1

[toc] | [prev] | [next] | [standalone]


#1503658 — Re: [PATCH 3/5] [media] winbond-cir: Move assignments for three variables in wbcir_shutdown()

From"David Härdeman" <david@hardeman.nu>
Date2016-10-19 16:30 +0200
SubjectRe: [PATCH 3/5] [media] winbond-cir: Move assignments for three variables in wbcir_shutdown()
Message-ID<stZSQ-2nd-163@gated-at.bofh.it>
In reply to#1500864
October 14, 2016 1:43 PM, "SF Markus Elfring" <elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 14 Oct 2016 10:40:12 +0200
> 
> Move the setting for the local variables "mask", "match" and "rc6_csl"
> behind the source code for a condition check by this function
> at the beginning.
 
Again, I can't see what the point is?

> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> drivers/media/rc/winbond-cir.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
> index fd997f0..9d05e17 100644
> --- a/drivers/media/rc/winbond-cir.c
> +++ b/drivers/media/rc/winbond-cir.c
> @@ -702,17 +702,17 @@ wbcir_shutdown(struct pnp_dev *device)
> bool do_wake = true;
> u8 match[11];
> u8 mask[11];
> - u8 rc6_csl = 0;
> + u8 rc6_csl;
> int i;
> 
> - memset(match, 0, sizeof(match));
> - memset(mask, 0, sizeof(mask));
> -
> if (wake_sc == INVALID_SCANCODE || !device_may_wakeup(dev)) {
> do_wake = false;
> goto finish;
> }
> 
> + rc6_csl = 0;
> + memset(match, 0, sizeof(match));
> + memset(mask, 0, sizeof(mask));
> switch (protocol) {
> case IR_PROTOCOL_RC5:
> if (wake_sc > 0xFFF) {
> -- 
> 2.10.1

[toc] | [prev] | [next] | [standalone]


#1503675 — Re: [media] winbond-cir: Move assignments for three variables in wbcir_shutdown()

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2016-10-19 16:30 +0200
SubjectRe: [media] winbond-cir: Move assignments for three variables in wbcir_shutdown()
Message-ID<stZSQ-2nd-161@gated-at.bofh.it>
In reply to#1503658
>> Move the setting for the local variables "mask", "match" and "rc6_csl"
>> behind the source code for a condition check by this function
>> at the beginning.
>  
> Again, I can't see what the point is?

* How do you think about to set these variables only after the initial
  check succeded?

* Do you care for data access locality?

Regards,
Markus

[toc] | [prev] | [next] | [standalone]


#1503958 — Re: [media] winbond-cir: Move assignments for three variables in wbcir_shutdown()

From"David Härdeman" <david@hardeman.nu>
Date2016-10-19 17:50 +0200
SubjectRe: [media] winbond-cir: Move assignments for three variables in wbcir_shutdown()
Message-ID<stZSQ-2nd-165@gated-at.bofh.it>
In reply to#1503675
October 19, 2016 3:38 PM, "SF Markus Elfring" <elfring@users.sourceforge.net> wrote:
>>> Move the setting for the local variables "mask", "match" and "rc6_csl"
>>> behind the source code for a condition check by this function
>>> at the beginning.
>> 
>> Again, I can't see what the point is?
> 
> * How do you think about to set these variables only after the initial
> check succeded?

I prefer setting variables early so that no thinking about whether they're initialized or not is necessary later. 

> * Do you care for data access locality?

Not unless you can show measurable performance improvements?

[toc] | [prev] | [next] | [standalone]


#1503631 — Re: [media] winbond-cir: Move a variable assignment in two functions

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2016-10-19 16:20 +0200
SubjectRe: [media] winbond-cir: Move a variable assignment in two functions
Message-ID<stZSP-2nd-117@gated-at.bofh.it>
In reply to#1500842
>> Move the assignment for the local variable "data" behind the source code
>> for condition checks by these functions.
> 
> Why?

* Would you like to set these variables only after the initial
  check succeeded?

* Do you care for data access locality also in these cases?

Regards,
Markus

[toc] | [prev] | [next] | [standalone]


#1503640 — Re: [media] winbond-cir: Move a variable assignment in wbcir_tx()

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2016-10-19 16:20 +0200
SubjectRe: [media] winbond-cir: Move a variable assignment in wbcir_tx()
Message-ID<stZSQ-2nd-137@gated-at.bofh.it>
In reply to#1500842
>> * How do you think about to avoid a variable assignment in case
>> that this memory allocation failed anyhow?
> 
> There is no memory allocation that can fail at this point.

Do you really know the failure probability for a call of the
function "kmalloc" (within the function "wbcir_tx") under all
possible run time situations?


>> * Do you care for data access locality?
> 
> Not unless you can show measurable performance improvements?

Did any software developer (before me) dare anything in this direction?

Regards,
Markus

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | linux.kernel


csiph-web