diff mbox

[04/13] DSPBRIDGE: fix macros that break when inside an if/else

Message ID 1247669795-23895-5-git-send-email-ameya.palande@nokia.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Ameya Palande July 15, 2009, 2:56 p.m. UTC
From: Doyu Hiroshi (Nokia-D/Helsinki) <hiroshi.doyu@nokia.com>

Based on the following discussion:
      http://marc.info/?l=linux-omap&m=124697893724881&w=2

Signed-off-by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
---
 drivers/dsp/bridge/pmgr/wcd.c |   60 ++++++++++++++++++++++++++--------------
 1 files changed, 39 insertions(+), 21 deletions(-)

Comments

Guzman Lugo, Fernando July 15, 2009, 9:51 p.m. UTC | #1
The patch looks good for me.

> -----Original Message-----
> From: Ameya Palande [mailto:ameya.palande@nokia.com]
> Sent: Wednesday, July 15, 2009 9:56 AM
> To: linux-omap@vger.kernel.org
> Cc: Ramirez Luna, Omar; Guzman Lugo, Fernando; Menon, Nishanth;
> hiroshi.doyu@nokia.com
> Subject: [PATCH 04/13] DSPBRIDGE: fix macros that break when inside an
> if/else
> 
> From: Doyu Hiroshi (Nokia-D/Helsinki) <hiroshi.doyu@nokia.com>
> 
> Based on the following discussion:
>       http://marc.info/?l=linux-omap&m=124697893724881&w=2
> 
> Signed-off-by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
> ---
>  drivers/dsp/bridge/pmgr/wcd.c |   60 ++++++++++++++++++++++++++----------
> ----
>  1 files changed, 39 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/dsp/bridge/pmgr/wcd.c b/drivers/dsp/bridge/pmgr/wcd.c
> index 441130c..8708c78 100644
> --- a/drivers/dsp/bridge/pmgr/wcd.c
> +++ b/drivers/dsp/bridge/pmgr/wcd.c
> @@ -145,27 +145,45 @@
>  #define MAX_STREAMS     16
>  #define MAX_BUFS	64
> 
> -/* Following two macros should ideally have do{}while(0) */
> -
> -#define cp_fm_usr(dest, src, status, elements)    \
> -    if (DSP_SUCCEEDED(status)) {\
> -	    if (unlikely(src == NULL) ||				\
> -		unlikely(copy_from_user(dest, src, elements *
> sizeof(*(dest))))) { \
> -		GT_1trace(WCD_debugMask, GT_7CLASS, \
> -		"copy_from_user failed, src=0x%x\n", src);  \
> -		status = DSP_EPOINTER ; \
> -	} \
> -    }
> -
> -#define cp_to_usr(dest, src, status, elements)    \
> -    if (DSP_SUCCEEDED(status)) {\
> -	    if (unlikely(dest == NULL) ||				\
> -		unlikely(copy_to_user(dest, src, elements * sizeof(*(src)))))
> { \
> -		GT_1trace(WCD_debugMask, GT_7CLASS, \
> -		"copy_to_user failed, dest=0x%x\n", dest); \
> -		status = DSP_EPOINTER ;\
> -	} \
> -    }
> +static inline void __cp_fm_usr(void *to, const void __user *from,
> +			       DSP_STATUS *err, unsigned long bytes)
> +{
> +	if (DSP_FAILED(*err))
> +		return;
> +
> +	if (unlikely(!from)) {
> +		*err = DSP_EPOINTER;
> +		return;
> +	}
> +
> +	if (unlikely(copy_from_user(to, from, bytes))) {
> +		GT_2trace(WCD_debugMask, GT_7CLASS,
> +			  "%s failed, from=0x%08x\n", __func__, from);
> +		*err = DSP_EPOINTER;
> +	}
> +}
> +#define cp_fm_usr(to, from, err, n)				\
> +	__cp_fm_usr(to, from, &(err), (n) * sizeof(*(to)))
> +
> +static inline void __cp_to_usr(void __user *to, const void *from,
> +			       DSP_STATUS *err, unsigned long bytes)
> +{
> +	if (DSP_FAILED(*err))
> +		return;
> +
> +	if (unlikely(!to)) {
> +		*err = DSP_EPOINTER;
> +		return;
> +	}
> +
> +	if (unlikely(copy_to_user(to, from, bytes))) {
> +		GT_2trace(WCD_debugMask, GT_7CLASS,
> +			  "%s failed, to=0x%08x\n", __func__, to);
> +		*err = DSP_EPOINTER;
> +	}
> +}
> +#define cp_to_usr(to, from, err, n)				\
> +	__cp_to_usr(to, from, &(err), (n) * sizeof(*(from)))
> 
>  /* Device IOCtl function pointer */
>  struct WCD_Cmd {
> --
> 1.6.2.4
> 
Acked-by Fernando Guzman Lugo <x0095840@ti.com>

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
omar ramirez July 19, 2009, 9:54 p.m. UTC | #2
>From: Ameya Palande [mailto:ameya.palande@nokia.com]
>Subject: [PATCH 04/13] DSPBRIDGE: fix macros that break when inside an if/else
>
>From: Doyu Hiroshi (Nokia-D/Helsinki) <hiroshi.doyu@nokia.com>
>
>Based on the following discussion:
>      http://marc.info/?l=linux-omap&m=124697893724881&w=2
>
>Signed-off-by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
>---
> drivers/dsp/bridge/pmgr/wcd.c |   60 ++++++++++++++++++++++++++--------------
> 1 files changed, 39 insertions(+), 21 deletions(-)
>

Fixed compiler error with debug enabled: "WCD_debugMask undeclared..."

Pushed to d.o-z

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

Patch

diff --git a/drivers/dsp/bridge/pmgr/wcd.c b/drivers/dsp/bridge/pmgr/wcd.c
index 441130c..8708c78 100644
--- a/drivers/dsp/bridge/pmgr/wcd.c
+++ b/drivers/dsp/bridge/pmgr/wcd.c
@@ -145,27 +145,45 @@ 
 #define MAX_STREAMS     16
 #define MAX_BUFS	64
 
-/* Following two macros should ideally have do{}while(0) */
-
-#define cp_fm_usr(dest, src, status, elements)    \
-    if (DSP_SUCCEEDED(status)) {\
-	    if (unlikely(src == NULL) ||				\
-		unlikely(copy_from_user(dest, src, elements * sizeof(*(dest))))) { \
-		GT_1trace(WCD_debugMask, GT_7CLASS, \
-		"copy_from_user failed, src=0x%x\n", src);  \
-		status = DSP_EPOINTER ; \
-	} \
-    }
-
-#define cp_to_usr(dest, src, status, elements)    \
-    if (DSP_SUCCEEDED(status)) {\
-	    if (unlikely(dest == NULL) ||				\
-		unlikely(copy_to_user(dest, src, elements * sizeof(*(src))))) { \
-		GT_1trace(WCD_debugMask, GT_7CLASS, \
-		"copy_to_user failed, dest=0x%x\n", dest); \
-		status = DSP_EPOINTER ;\
-	} \
-    }
+static inline void __cp_fm_usr(void *to, const void __user *from,
+			       DSP_STATUS *err, unsigned long bytes)
+{
+	if (DSP_FAILED(*err))
+		return;
+
+	if (unlikely(!from)) {
+		*err = DSP_EPOINTER;
+		return;
+	}
+
+	if (unlikely(copy_from_user(to, from, bytes))) {
+		GT_2trace(WCD_debugMask, GT_7CLASS,
+			  "%s failed, from=0x%08x\n", __func__, from);
+		*err = DSP_EPOINTER;
+	}
+}
+#define cp_fm_usr(to, from, err, n)				\
+	__cp_fm_usr(to, from, &(err), (n) * sizeof(*(to)))
+
+static inline void __cp_to_usr(void __user *to, const void *from,
+			       DSP_STATUS *err, unsigned long bytes)
+{
+	if (DSP_FAILED(*err))
+		return;
+
+	if (unlikely(!to)) {
+		*err = DSP_EPOINTER;
+		return;
+	}
+
+	if (unlikely(copy_to_user(to, from, bytes))) {
+		GT_2trace(WCD_debugMask, GT_7CLASS,
+			  "%s failed, to=0x%08x\n", __func__, to);
+		*err = DSP_EPOINTER;
+	}
+}
+#define cp_to_usr(to, from, err, n)				\
+	__cp_to_usr(to, from, &(err), (n) * sizeof(*(from)))
 
 /* Device IOCtl function pointer */
 struct WCD_Cmd {