From patchwork Tue Jun 20 16:50:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dhananjay Balan X-Patchwork-Id: 9799991 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 029CD60329 for ; Tue, 20 Jun 2017 17:01:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBED423F88 for ; Tue, 20 Jun 2017 17:01:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEB4026223; Tue, 20 Jun 2017 17:01:00 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 46D1623F88 for ; Tue, 20 Jun 2017 17:01:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750859AbdFTRA7 (ORCPT ); Tue, 20 Jun 2017 13:00:59 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:40905 "EHLO out3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750773AbdFTRA6 (ORCPT ); Tue, 20 Jun 2017 13:00:58 -0400 X-Greylist: delayed 540 seconds by postgrey-1.27 at vger.kernel.org; Tue, 20 Jun 2017 13:00:58 EDT Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id E09432097C; Tue, 20 Jun 2017 12:51:57 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute1.internal (MEProxy); Tue, 20 Jun 2017 12:51:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dbalan.in; h=cc :date:from:message-id:subject:to:x-me-sender:x-me-sender :x-sasl-enc:x-sasl-enc; s=mesmtp; bh=ew3Qx2Aq0GRbXXAxGrygcCMG91u k1EvSAMumXwQzGkU=; b=deXj2r61jqXAbLi1KEnVtF0wXUy0ovK85H6GdfSudkx RBQXRzwM1Rtjf53ZMGN0KqLvhnvLG1qkv+/iFDbAPM49Y1UNNiGnYugGVvN7CPdl 6fUii0iCPK8M7NKNvdrTglzjmUpXxdR4VtJIkkVYZvGM5XT2FmVfKqY6a9c3D1tY = DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:message-id:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=ew3Qx2 Aq0GRbXXAxGrygcCMG91uk1EvSAMumXwQzGkU=; b=Vjs0Y48Esz0nW7hdiLH5G8 2M1lFMIDrpyihbaIFAmmtFLFDiyf6yawRzvogyzDcFdg6YDF6QyUHiDVNSKao5BD LO1J3VUIQhNIkmkL+ZQ7wgdl2Yjfxpd4NIfQY+zAAKfrquJzkPefgOFEH53dHu7W 32zGIdQkF12UyZNWX1VaDKo3N7y2PpiXV+vhuqWKQ0Oe3PCY6/y6pjd95qoMLZOR /28NvCT6VJxrHqKFSjveoZgPrmz53hV73XVceNJ8APS1ZWqbotegaT+tRpCYgoZH mQTzxbSwFbgAgrWPwekN/dSYaqTEHm6J7VmCMqQtIXlBlS2iNoSYaWNVas3Er/xA == X-ME-Sender: X-Sasl-enc: 5rrQFSIjzjkzIh0YGdy8W3OJFR7NNNAHlykunPX1JcBi 1497977517 Received: from localhost (p5b05be47.dip0.t-ipconnect.de [91.5.190.71]) by mail.messagingengine.com (Postfix) with ESMTPA id 59B2F2480D; Tue, 20 Jun 2017 12:51:57 -0400 (EDT) From: Dhananjay Balan To: sudipm.mukherjee@gmail.com Cc: teddy.wang@siliconmotion.com, gregkh@linuxfoundation.org, linux-fbdev@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Dhananjay Balan Subject: [PATCH] staging: sm750fb: move common locking code to a macro Date: Tue, 20 Jun 2017 18:50:13 +0200 Message-Id: <20170620165013.11013-1-mail@dbalan.in> X-Mailer: git-send-email 2.13.1 Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The locking and unlocking code used by copy routines is common, so moved it to a macro. Signed-off-by: Dhananjay Balan --- drivers/staging/sm750fb/sm750.c | 81 ++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 50 deletions(-) diff --git a/drivers/staging/sm750fb/sm750.c b/drivers/staging/sm750fb/sm750.c index 386d4adcd91d..d8ab83aea46d 100644 --- a/drivers/staging/sm750fb/sm750.c +++ b/drivers/staging/sm750fb/sm750.c @@ -156,12 +156,25 @@ static int lynxfb_ops_cursor(struct fb_info *info, struct fb_cursor *fbcursor) return 0; } +/* + * If not using spin_lock, system will die if user frequently loads and + * immediately unloads driver (dual) + */ +#define dual_safe_call(func, ...) \ + do { \ + if (sm750_dev->fb_count > 1) \ + spin_lock(&sm750_dev->slock); \ + func(__VA_ARGS__); \ + if (sm750_dev->fb_count > 1) \ + spin_unlock(&sm750_dev->slock); \ + } while (0) + static void lynxfb_ops_fillrect(struct fb_info *info, const struct fb_fillrect *region) { struct lynxfb_par *par; struct sm750_dev *sm750_dev; - unsigned int base, pitch, Bpp, rop; + unsigned int base, pitch, bit_pp, rop; u32 color; if (info->state != FBINFO_STATE_RUNNING) @@ -176,26 +189,15 @@ static void lynxfb_ops_fillrect(struct fb_info *info, */ base = par->crtc.oScreen; pitch = info->fix.line_length; - Bpp = info->var.bits_per_pixel >> 3; + bit_pp = info->var.bits_per_pixel >> 3; - color = (Bpp == 1) ? region->color : + color = (bit_pp == 1) ? region->color : ((u32 *)info->pseudo_palette)[region->color]; rop = (region->rop != ROP_COPY) ? HW_ROP2_XOR : HW_ROP2_COPY; - /* - * If not use spin_lock,system will die if user load driver - * and immediately unload driver frequently (dual) - */ - if (sm750_dev->fb_count > 1) - spin_lock(&sm750_dev->slock); - - sm750_dev->accel.de_fillrect(&sm750_dev->accel, - base, pitch, Bpp, - region->dx, region->dy, - region->width, region->height, - color, rop); - if (sm750_dev->fb_count > 1) - spin_unlock(&sm750_dev->slock); + dual_safe_call(sm750_dev->accel.de_fillrect, &sm750_dev->accel, + base, pitch, bit_pp, region->dx, region->dy, + region->width, region->height, color, rop); } static void lynxfb_ops_copyarea(struct fb_info *info, @@ -203,7 +205,7 @@ static void lynxfb_ops_copyarea(struct fb_info *info, { struct lynxfb_par *par; struct sm750_dev *sm750_dev; - unsigned int base, pitch, Bpp; + unsigned int base, pitch, bit_pp; par = info->par; sm750_dev = par->dev; @@ -214,28 +216,18 @@ static void lynxfb_ops_copyarea(struct fb_info *info, */ base = par->crtc.oScreen; pitch = info->fix.line_length; - Bpp = info->var.bits_per_pixel >> 3; + bit_pp = info->var.bits_per_pixel >> 3; - /* - * If not use spin_lock, system will die if user load driver - * and immediately unload driver frequently (dual) - */ - if (sm750_dev->fb_count > 1) - spin_lock(&sm750_dev->slock); - - sm750_dev->accel.de_copyarea(&sm750_dev->accel, - base, pitch, region->sx, region->sy, - base, pitch, Bpp, region->dx, region->dy, - region->width, region->height, - HW_ROP2_COPY); - if (sm750_dev->fb_count > 1) - spin_unlock(&sm750_dev->slock); + dual_safe_call(sm750_dev->accel.de_copyarea, &sm750_dev->accel, + base, pitch, region->sx, region->sy, + base, pitch, bit_pp, region->dx, region->dy, + region->width, region->height, HW_ROP2_COPY); } static void lynxfb_ops_imageblit(struct fb_info *info, const struct fb_image *image) { - unsigned int base, pitch, Bpp; + unsigned int base, pitch, bit_pp; unsigned int fgcol, bgcol; struct lynxfb_par *par; struct sm750_dev *sm750_dev; @@ -248,7 +240,7 @@ static void lynxfb_ops_imageblit(struct fb_info *info, */ base = par->crtc.oScreen; pitch = info->fix.line_length; - Bpp = info->var.bits_per_pixel >> 3; + bit_pp = info->var.bits_per_pixel >> 3; /* TODO: Implement hardware acceleration for image->depth > 1 */ if (image->depth != 1) { @@ -265,21 +257,10 @@ static void lynxfb_ops_imageblit(struct fb_info *info, bgcol = image->bg_color; } - /* - * If not use spin_lock, system will die if user load driver - * and immediately unload driver frequently (dual) - */ - if (sm750_dev->fb_count > 1) - spin_lock(&sm750_dev->slock); - - sm750_dev->accel.de_imageblit(&sm750_dev->accel, - image->data, image->width >> 3, 0, - base, pitch, Bpp, - image->dx, image->dy, - image->width, image->height, - fgcol, bgcol, HW_ROP2_COPY); - if (sm750_dev->fb_count > 1) - spin_unlock(&sm750_dev->slock); + dual_safe_call(sm750_dev->accel.de_imageblit, &sm750_dev->accel, + image->data, image->width >> 3, 0, base, pitch, + bit_pp, image->dx, image->dy, image->width, + image->height, fgcol, bgcol, HW_ROP2_COPY); } static int lynxfb_ops_pan_display(struct fb_var_screeninfo *var,