From patchwork Thu Jun 2 04:24:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binoy Jayan X-Patchwork-Id: 69119 Delivered-To: patch@linaro.org Received: by 10.140.23.41 with SMTP id 38csp134690qgo; Wed, 1 Jun 2016 21:25:06 -0700 (PDT) X-Received: by 10.66.152.164 with SMTP id uz4mr2626502pab.9.1464841506391; Wed, 01 Jun 2016 21:25:06 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id un5si47583439pab.174.2016.06.01.21.25.06; Wed, 01 Jun 2016 21:25:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751412AbcFBEYx (ORCPT + 30 others); Thu, 2 Jun 2016 00:24:53 -0400 Received: from mail-pa0-f54.google.com ([209.85.220.54]:33249 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750914AbcFBEYj (ORCPT ); Thu, 2 Jun 2016 00:24:39 -0400 Received: by mail-pa0-f54.google.com with SMTP id um11so2432855pab.0 for ; Wed, 01 Jun 2016 21:24:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RMp6q73y74O6SHFJOy5BMfIuLnC5ZkQy8hmMJNS4nJc=; b=NvD2xBfySqfkXb1tKaEUTXEEyAB9uTqZUbtznzreqQczeZqQkNYTgLxyevMUxlolcu v1Vupo7ETLOO1qYS+4yVhcH3l5prqjV37XwcKpPe6YNHJwoeR9nzPb74w4/Obbm3/m6h G+qR8Jv+19wdVKC/7KeoQ/rjt+favXUS2vL7I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RMp6q73y74O6SHFJOy5BMfIuLnC5ZkQy8hmMJNS4nJc=; b=Mkc19n338BrxbO82CKO1MJzag31odeQe9RtfooUP0gPZNxtMBCBN/6qTfpR+1rhf4f L3l4Vln3CEi0jT5qXoYxG+gG5+DoumneNs+y95+koeg7fcth/J6pUypC0Mf1x7t1HhFT PILA32tuGbb23q4CfK5hfzQTfm0Eq5fidDpHr7aACGHLifBdrsrBItFj55xGOsGhrGLk /l92Clnv77TdvoahiLmP69p+HSd7BmiU+/i1YVSD51Wb5RRozKd/Yf4qGDCZfXu9qqpw XnXlXbmGRd3f6B7FwAsZ1Mhz/IKhRXtPqUrRA+Ga66Ojcb2hK2wnWbiW9HNH4fpuXF8o m7MA== X-Gm-Message-State: ALyK8tJB00FnTitCQLKu/NIJaANtjaW827e0qJERNPi0yevk8U8q+nj4EPGtsepG/TrjY8Fi X-Received: by 10.66.65.133 with SMTP id x5mr2720873pas.108.1464841479200; Wed, 01 Jun 2016 21:24:39 -0700 (PDT) Received: from blr-ubuntu-59.ap.qualcomm.com ([202.46.23.61]) by smtp.gmail.com with ESMTPSA id s86sm36652609pfi.69.2016.06.01.21.24.35 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 01 Jun 2016 21:24:38 -0700 (PDT) From: Binoy Jayan To: Greg Kroah-Hartman , Larry Finger , Florian Schilhabel Cc: Arnd Bergmann , driverdev-devel@linuxdriverproject.org, linux-kernel@vger.kernel.org, Binoy Jayan Subject: [PATCH v2 4/4] rtl8712: pwrctrl_priv: Replace semaphore lock with mutex Date: Thu, 2 Jun 2016 09:54:10 +0530 Message-Id: <1464841450-24772-5-git-send-email-binoy.jayan@linaro.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1464841450-24772-1-git-send-email-binoy.jayan@linaro.org> References: <1464841450-24772-1-git-send-email-binoy.jayan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The semaphore 'lock' in 'pwrctrl_priv' is used as a simple mutex, so it should be written as one. Semaphores are going away in the future. _enter_pwrlock was using down_interruptible(), so the lock could be broken by sending a signal. This could be a bug, because nothing checks the return code here. Hence, using mutex_lock instead of the interruptible version. Removing the now unused _enter_pwrlock and _down_sema. Signed-off-by: Binoy Jayan --- This patch depends on the following patch: rtl8712: intf_priv: Replace semaphore lock with completion drivers/staging/rtl8712/osdep_service.h | 7 ------- drivers/staging/rtl8712/rtl8712_cmd.c | 10 +++++----- drivers/staging/rtl8712/rtl871x_pwrctrl.c | 22 +++++++++++----------- drivers/staging/rtl8712/rtl871x_pwrctrl.h | 7 +------ 4 files changed, 17 insertions(+), 29 deletions(-) -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project diff --git a/drivers/staging/rtl8712/osdep_service.h b/drivers/staging/rtl8712/osdep_service.h index 076d508..d89ae09 100644 --- a/drivers/staging/rtl8712/osdep_service.h +++ b/drivers/staging/rtl8712/osdep_service.h @@ -60,13 +60,6 @@ struct __queue { #define LIST_CONTAINOR(ptr, type, member) \ ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member))) -static inline u32 _down_sema(struct semaphore *sema) -{ - if (down_interruptible(sema)) - return _FAIL; - return _SUCCESS; -} - static inline u32 end_of_queue_search(struct list_head *head, struct list_head *plist) { diff --git a/drivers/staging/rtl8712/rtl8712_cmd.c b/drivers/staging/rtl8712/rtl8712_cmd.c index 1badc6c..9934eab 100644 --- a/drivers/staging/rtl8712/rtl8712_cmd.c +++ b/drivers/staging/rtl8712/rtl8712_cmd.c @@ -264,9 +264,9 @@ static struct cmd_obj *cmd_hdl_filter(struct _adapter *padapter, */ if (padapter->pwrctrlpriv.pwr_mode > PS_MODE_ACTIVE) { padapter->pwrctrlpriv.pwr_mode = PS_MODE_ACTIVE; - _enter_pwrlock(&(padapter->pwrctrlpriv.lock)); + mutex_lock(&padapter->pwrctrlpriv.mutex_lock); r8712_set_rpwm(padapter, PS_STATE_S4); - up(&(padapter->pwrctrlpriv.lock)); + mutex_unlock(&padapter->pwrctrlpriv.mutex_lock); } pcmd_r = pcmd; break; @@ -395,10 +395,10 @@ _next: } if (pcmd->cmdcode == GEN_CMD_CODE(_SetPwrMode)) { if (padapter->pwrctrlpriv.bSleep) { - _enter_pwrlock(&(padapter-> - pwrctrlpriv.lock)); + mutex_lock(&padapter-> + pwrctrlpriv.mutex_lock); r8712_set_rpwm(padapter, PS_STATE_S2); - up(&padapter->pwrctrlpriv.lock); + mutex_unlock(&padapter->pwrctrlpriv.mutex_lock); } } r8712_free_cmd_obj(pcmd); diff --git a/drivers/staging/rtl8712/rtl871x_pwrctrl.c b/drivers/staging/rtl8712/rtl871x_pwrctrl.c index 98a5e74..8d7ead6 100644 --- a/drivers/staging/rtl8712/rtl871x_pwrctrl.c +++ b/drivers/staging/rtl8712/rtl871x_pwrctrl.c @@ -103,14 +103,14 @@ void r8712_cpwm_int_hdl(struct _adapter *padapter, if (pwrpriv->cpwm_tog == ((preportpwrstate->state) & 0x80)) return; del_timer(&padapter->pwrctrlpriv.rpwm_check_timer); - _enter_pwrlock(&pwrpriv->lock); + mutex_lock(&pwrpriv->mutex_lock); pwrpriv->cpwm = (preportpwrstate->state) & 0xf; if (pwrpriv->cpwm >= PS_STATE_S2) { if (pwrpriv->alives & CMD_ALIVE) complete(&(pcmdpriv->cmd_queue_comp)); } pwrpriv->cpwm_tog = (preportpwrstate->state) & 0x80; - up(&pwrpriv->lock); + mutex_unlock(&pwrpriv->mutex_lock); } static inline void register_task_alive(struct pwrctrl_priv *pwrctrl, uint tag) @@ -141,10 +141,10 @@ static void SetPSModeWorkItemCallback(struct work_struct *work) struct _adapter *padapter = container_of(pwrpriv, struct _adapter, pwrctrlpriv); if (!pwrpriv->bSleep) { - _enter_pwrlock(&pwrpriv->lock); + mutex_lock(&pwrpriv->mutex_lock); if (pwrpriv->pwr_mode == PS_MODE_ACTIVE) r8712_set_rpwm(padapter, PS_STATE_S4); - up(&pwrpriv->lock); + mutex_lock(&pwrpriv->mutex_lock); } } @@ -155,11 +155,11 @@ static void rpwm_workitem_callback(struct work_struct *work) struct _adapter *padapter = container_of(pwrpriv, struct _adapter, pwrctrlpriv); if (pwrpriv->cpwm != pwrpriv->rpwm) { - _enter_pwrlock(&pwrpriv->lock); + mutex_lock(&pwrpriv->mutex_lock); r8712_read8(padapter, SDIO_HCPWM); pwrpriv->rpwm_retry = 1; r8712_set_rpwm(padapter, pwrpriv->rpwm); - up(&pwrpriv->lock); + mutex_unlock(&pwrpriv->mutex_lock); } } @@ -175,7 +175,7 @@ void r8712_init_pwrctrl_priv(struct _adapter *padapter) struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv; memset((unsigned char *)pwrctrlpriv, 0, sizeof(struct pwrctrl_priv)); - sema_init(&pwrctrlpriv->lock, 1); + mutex_init(&pwrctrlpriv->mutex_lock); pwrctrlpriv->cpwm = PS_STATE_S4; pwrctrlpriv->pwr_mode = PS_MODE_ACTIVE; pwrctrlpriv->smart_ps = 0; @@ -207,13 +207,13 @@ sint r8712_register_cmd_alive(struct _adapter *padapter) uint res = _SUCCESS; struct pwrctrl_priv *pwrctrl = &padapter->pwrctrlpriv; - _enter_pwrlock(&pwrctrl->lock); + mutex_lock(&pwrctrl->mutex_lock); register_task_alive(pwrctrl, CMD_ALIVE); if (pwrctrl->cpwm < PS_STATE_S2) { r8712_set_rpwm(padapter, PS_STATE_S3); res = _FAIL; } - up(&pwrctrl->lock); + mutex_unlock(&pwrctrl->mutex_lock); return res; } @@ -229,7 +229,7 @@ void r8712_unregister_cmd_alive(struct _adapter *padapter) { struct pwrctrl_priv *pwrctrl = &padapter->pwrctrlpriv; - _enter_pwrlock(&pwrctrl->lock); + mutex_lock(&pwrctrl->mutex_lock); unregister_task_alive(pwrctrl, CMD_ALIVE); if ((pwrctrl->cpwm > PS_STATE_S2) && (pwrctrl->pwr_mode > PS_MODE_ACTIVE)) { @@ -239,5 +239,5 @@ void r8712_unregister_cmd_alive(struct _adapter *padapter) r8712_set_rpwm(padapter, PS_STATE_S0); } } - up(&pwrctrl->lock); + mutex_unlock(&pwrctrl->mutex_lock); } diff --git a/drivers/staging/rtl8712/rtl871x_pwrctrl.h b/drivers/staging/rtl8712/rtl871x_pwrctrl.h index dbfb555..231445e 100644 --- a/drivers/staging/rtl8712/rtl871x_pwrctrl.h +++ b/drivers/staging/rtl8712/rtl871x_pwrctrl.h @@ -87,13 +87,8 @@ struct reportpwrstate_parm { unsigned short rsvd; }; -static inline void _enter_pwrlock(struct semaphore *plock) -{ - _down_sema(plock); -} - struct pwrctrl_priv { - struct semaphore lock; + struct mutex mutex_lock; /*volatile*/ u8 rpwm; /* requested power state for fw */ /* fw current power state. updated when 1. read from HCPWM or * 2. driver lowers power level */