From patchwork Wed Jul 15 14:56:27 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ameya Palande X-Patchwork-Id: 35695 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n6FEufub024812 for ; Wed, 15 Jul 2009 14:56:41 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755199AbZGOO4j (ORCPT ); Wed, 15 Jul 2009 10:56:39 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755207AbZGOO4j (ORCPT ); Wed, 15 Jul 2009 10:56:39 -0400 Received: from smtp.nokia.com ([192.100.105.134]:61029 "EHLO mgw-mx09.nokia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755199AbZGOO4j (ORCPT ); Wed, 15 Jul 2009 10:56:39 -0400 Received: from esebh106.NOE.Nokia.com (esebh106.ntc.nokia.com [172.21.138.213]) by mgw-mx09.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id n6FEuSZm016935; Wed, 15 Jul 2009 09:56:32 -0500 Received: from vaebh104.NOE.Nokia.com ([10.160.244.30]) by esebh106.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 15 Jul 2009 17:56:35 +0300 Received: from mgw-sa01.ext.nokia.com ([147.243.1.47]) by vaebh104.NOE.Nokia.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Wed, 15 Jul 2009 17:56:34 +0300 Received: from localhost.localdomain (esdhcp04048.research.nokia.com [172.21.40.48]) by mgw-sa01.ext.nokia.com (Switch-3.2.6/Switch-3.2.6) with ESMTP id n6FEuQeX018779; Wed, 15 Jul 2009 17:56:32 +0300 From: Ameya Palande To: linux-omap@vger.kernel.org Cc: omar.ramirez@ti.com, x0095840@ti.com, nm@ti.com, hiroshi.doyu@nokia.com Subject: [PATCH 04/13] DSPBRIDGE: fix macros that break when inside an if/else Date: Wed, 15 Jul 2009 17:56:27 +0300 Message-Id: <1247669795-23895-5-git-send-email-ameya.palande@nokia.com> X-Mailer: git-send-email 1.6.2.4 In-Reply-To: <1247669795-23895-4-git-send-email-ameya.palande@nokia.com> References: <1247669795-23895-1-git-send-email-ameya.palande@nokia.com> <1247669795-23895-2-git-send-email-ameya.palande@nokia.com> <1247669795-23895-3-git-send-email-ameya.palande@nokia.com> <1247669795-23895-4-git-send-email-ameya.palande@nokia.com> X-OriginalArrivalTime: 15 Jul 2009 14:56:34.0930 (UTC) FILETIME=[727B6520:01CA055C] X-Nokia-AV: Clean Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org From: Doyu Hiroshi (Nokia-D/Helsinki) Based on the following discussion: http://marc.info/?l=linux-omap&m=124697893724881&w=2 Signed-off-by: Hiroshi DOYU --- 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 {