From patchwork Wed Jan 16 21:11:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pawe=C5=82_Chmiel?= X-Patchwork-Id: 10766933 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B74166C2 for ; Wed, 16 Jan 2019 21:11:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6D652F5DD for ; Wed, 16 Jan 2019 21:11:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9AE422F5DE; Wed, 16 Jan 2019 21:11:47 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 2F05B2F5CC for ; Wed, 16 Jan 2019 21:11:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727342AbfAPVLp (ORCPT ); Wed, 16 Jan 2019 16:11:45 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:38464 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726924AbfAPVLp (ORCPT ); Wed, 16 Jan 2019 16:11:45 -0500 Received: by mail-lj1-f196.google.com with SMTP id c19-v6so6701834lja.5; Wed, 16 Jan 2019 13:11:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=mZC/R8I02rqLCUVmu/Wi64L1mcvQxP71e+q0r7wmFss=; b=NAQg3wWIq+52aPeHZCAO8VsN9ZCQJnLSamPyV10aZTXLvoEAJJ2VsWl/7zTpU/8vWZ qmsAp+e7JqzR6arfg/Yof+4JVLmpkCRnVZNw196a7kanTfkTbI5a/XeFR5v6s7bU0xVf x2Hs4c/v6EmOrmTkrFDt/CGaikJOo9+SOXkMAn5jIjgGFhmWMCIKVFAli9Cq4Uxcal8c RiJohvfepnhiEj6X2uZYjXqz8R42sUzhvXz7noHaC+XKWH9pehlI91TSpvlrpwylKYqE pZKU1re53q8MpPu54McCkJ7iTwMBpoLmdXRYvwOixdJhNCGinv2eZcv0TK4CcVXdBgzG orCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=mZC/R8I02rqLCUVmu/Wi64L1mcvQxP71e+q0r7wmFss=; b=gHWLS0CGA0JKdnh3HgcPj6C/iXcb5PfZXNj3jYlA22qIeljB+EyK/6N1dxSUxKAT7D sd3Uey0o4pDH3fGoe6Whb2RTItr3lAvAN/vh+SQphUyH0Ysbcy1JgmgMXtJ6g3xi/WBg AeTBU8GMeRYJYSRVoeerbBuWKvh/IfQoRfT55Se8dPCSI2HT9WQvoFWklBW5loITyUUJ D9DZmKFdDOa+xVOK4//27tVQRj04GyaeUuvy1oMAYU5dnYgtABLkZrJuuX/A3PKeFEhx 1MnsJdeqp8u64ZwdJsFWL69ymXlNiSZt1m29bBL17Rjm14UoIK6fmGmL6R4o4V0gXXoY l91g== X-Gm-Message-State: AJcUukesuHld8d3ASGK6MuGCNbx0v589anA6IGrzM0Cu5fAiT0ZhceNY TU0xkqKjUDcSQGPTY6FTVPw= X-Google-Smtp-Source: ALg8bN58rQr8MjHbIKHJf+YJqFD/Ai9cXHn5DcRaMq+07eICYl/wtyuNRo1tXTVBtdnD42eNeawgaA== X-Received: by 2002:a2e:84ca:: with SMTP id q10-v6mr7821129ljh.65.1547673102633; Wed, 16 Jan 2019 13:11:42 -0800 (PST) Received: from localhost.localdomain ([2a02:a315:5445:5300:6c79:3c25:1ea9:fa4b]) by smtp.googlemail.com with ESMTPSA id a20-v6sm1221524ljf.28.2019.01.16.13.11.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Jan 2019 13:11:41 -0800 (PST) From: =?utf-8?q?Pawe=C5=82_Chmiel?= To: dmitry.torokhov@gmail.com Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Bakker , =?utf-8?q?Pawe=C5=82_Chmiel?= Subject: [PATCH] input: misc: pwm-vibra: Prevent unbalanced regulator Date: Wed, 16 Jan 2019 22:11:31 +0100 Message-Id: <20190116211131.18809-1-pawel.mikolaj.chmiel@gmail.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jonathan Bakker pwm_vibrator_stop disables the regulator, but it can be called from multiple places, even when the regulator is already disabled. Fix this by using regulator_is_enabled check when starting and stopping device. Signed-off-by: Jonathan Bakker Signed-off-by: Paweł Chmiel --- drivers/input/misc/pwm-vibra.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/input/misc/pwm-vibra.c b/drivers/input/misc/pwm-vibra.c index 55da191ae550..66677ee770ca 100644 --- a/drivers/input/misc/pwm-vibra.c +++ b/drivers/input/misc/pwm-vibra.c @@ -42,10 +42,12 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator) struct pwm_state state; int err; - err = regulator_enable(vibrator->vcc); - if (err) { - dev_err(pdev, "failed to enable regulator: %d", err); - return err; + if (!regulator_is_enabled(vibrator->vcc)) { + err = regulator_enable(vibrator->vcc); + if (err) { + dev_err(pdev, "failed to enable regulator: %d", err); + return err; + } } pwm_get_state(vibrator->pwm, &state); @@ -76,7 +78,8 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator) static void pwm_vibrator_stop(struct pwm_vibrator *vibrator) { - regulator_disable(vibrator->vcc); + if (regulator_is_enabled(vibrator->vcc)) + regulator_disable(vibrator->vcc); if (vibrator->pwm_dir) pwm_disable(vibrator->pwm_dir);