From patchwork Fri Apr 6 14:23:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10326793 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2970960545 for ; Fri, 6 Apr 2018 14:24:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1AC032953A for ; Fri, 6 Apr 2018 14:24:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0ECF52953E; Fri, 6 Apr 2018 14:24:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A00E92953A for ; Fri, 6 Apr 2018 14:24:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756698AbeDFOXe (ORCPT ); Fri, 6 Apr 2018 10:23:34 -0400 Received: from osg.samsung.com ([64.30.133.232]:36574 "EHLO osg.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756352AbeDFOXa (ORCPT ); Fri, 6 Apr 2018 10:23:30 -0400 Received: from localhost (localhost [127.0.0.1]) by osg.samsung.com (Postfix) with ESMTP id 0E00C32CB0; Fri, 6 Apr 2018 07:23:30 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at dev.s-opensource.com X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from osg.samsung.com ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aMGBr4GvfJ39; Fri, 6 Apr 2018 07:23:29 -0700 (PDT) Received: from smtp.s-opensource.com (177.17.251.195.dynamic.adsl.gvt.net.br [177.17.251.195]) by osg.samsung.com (Postfix) with ESMTPSA id 86BD032C65; Fri, 6 Apr 2018 07:23:26 -0700 (PDT) Received: from mchehab by smtp.s-opensource.com with local (Exim 4.90_1) (envelope-from ) id 1f4SGy-0008Xh-HW; Fri, 06 Apr 2018 10:23:24 -0400 From: Mauro Carvalho Chehab Cc: Mauro Carvalho Chehab , Linux Media Mailing List , Mauro Carvalho Chehab , Greg Kroah-Hartman , devel@driverdev.osuosl.org Subject: [PATCH 09/21] media: davinci_vpfe: cleanup ipipe_[g|s]_config logic Date: Fri, 6 Apr 2018 10:23:10 -0400 Message-Id: <3200bc234f8732c14a5e31d44b8e9f3262df4fb4.1523024380.git.mchehab@s-opensource.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: References: In-Reply-To: References: To: unlisted-recipients:; (no To-header on input) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Reduce one ident level inside those functions and use BIT() macro. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/media/davinci_vpfe/dm365_ipipe.c | 98 ++++++++++++------------ 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c index b3a193ddd778..a7043865cf06 100644 --- a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c +++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c @@ -27,6 +27,7 @@ */ #include +#include #include "dm365_ipipe.h" #include "dm365_ipipe_hw.h" @@ -1255,37 +1256,38 @@ static int ipipe_s_config(struct v4l2_subdev *sd, struct vpfe_ipipe_config *cfg) int rval = 0; for (i = 0; i < ARRAY_SIZE(ipipe_modules); i++) { - unsigned int bit = 1 << i; + const struct ipipe_module_if *module_if; + struct ipipe_module_params *params; + void __user *from; + size_t size; + void *to; - if (cfg->flag & bit) { - const struct ipipe_module_if *module_if = - &ipipe_modules[i]; - struct ipipe_module_params *params; - void __user *from = *(void * __user *) - ((void *)cfg + module_if->config_offset); - size_t size; - void *to; + if (!(cfg->flag & BIT(i))) + continue; - params = kmalloc(sizeof(struct ipipe_module_params), - GFP_KERNEL); - to = (void *)params + module_if->param_offset; - size = module_if->param_size; + module_if = &ipipe_modules[i]; + from = *(void * __user *) + ((void *)cfg + module_if->config_offset); - if (to && from && size) { - if (copy_from_user(to, from, size)) { - rval = -EFAULT; - break; - } - rval = module_if->set(ipipe, to); - if (rval) - goto error; - } else if (to && !from && size) { - rval = module_if->set(ipipe, NULL); - if (rval) - goto error; + params = kmalloc(sizeof(struct ipipe_module_params), + GFP_KERNEL); + to = (void *)params + module_if->param_offset; + size = module_if->param_size; + + if (to && from && size) { + if (copy_from_user(to, from, size)) { + rval = -EFAULT; + break; } - kfree(params); + rval = module_if->set(ipipe, to); + if (rval) + goto error; + } else if (to && !from && size) { + rval = module_if->set(ipipe, NULL); + if (rval) + goto error; } + kfree(params); } error: return rval; @@ -1298,33 +1300,33 @@ static int ipipe_g_config(struct v4l2_subdev *sd, struct vpfe_ipipe_config *cfg) int rval = 0; for (i = 1; i < ARRAY_SIZE(ipipe_modules); i++) { - unsigned int bit = 1 << i; + const struct ipipe_module_if *module_if; + struct ipipe_module_params *params; + void __user *to; + size_t size; + void *from; - if (cfg->flag & bit) { - const struct ipipe_module_if *module_if = - &ipipe_modules[i]; - struct ipipe_module_params *params; - void __user *to = *(void * __user *) - ((void *)cfg + module_if->config_offset); - size_t size; - void *from; + if (!(cfg->flag & BIT(i))) + continue; - params = kmalloc(sizeof(struct ipipe_module_params), - GFP_KERNEL); - from = (void *)params + module_if->param_offset; - size = module_if->param_size; + module_if = &ipipe_modules[i]; + to = *(void * __user *)((void *)cfg + module_if->config_offset); - if (to && from && size) { - rval = module_if->get(ipipe, from); - if (rval) - goto error; - if (copy_to_user(to, from, size)) { - rval = -EFAULT; - break; - } + params = kmalloc(sizeof(struct ipipe_module_params), + GFP_KERNEL); + from = (void *)params + module_if->param_offset; + size = module_if->param_size; + + if (to && from && size) { + rval = module_if->get(ipipe, from); + if (rval) + goto error; + if (copy_to_user(to, from, size)) { + rval = -EFAULT; + break; } - kfree(params); } + kfree(params); } error: return rval;