From patchwork Tue Feb 5 22:20:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 10798563 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 312421669 for ; Tue, 5 Feb 2019 22:20:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F8F62CAA5 for ; Tue, 5 Feb 2019 22:20:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 135B32CAB7; Tue, 5 Feb 2019 22:20:56 +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 A12E32CAA5 for ; Tue, 5 Feb 2019 22:20:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727393AbfBEWUz (ORCPT ); Tue, 5 Feb 2019 17:20:55 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:33877 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726742AbfBEWUz (ORCPT ); Tue, 5 Feb 2019 17:20:55 -0500 Received: by mail-pg1-f193.google.com with SMTP id d9so2029003pgl.1; Tue, 05 Feb 2019 14:20:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=VsW4w9Tidh8kQF/wOzdszRJTB9PdDmdFIqsfVlGud5k=; b=Qp6bICfo6VCKyysBjCiL+FTycKf9OsHR4/hi5pi1dlZ9iWGuC2QOxdNe5KA/dgaG5R unpaRLrfOYGIrknLm8JFsNODvdlGmIq3uyX1f7w9Nza+MwFOnmE87AsPR8FVyZLv/xML RSKDSt8GE7zk5DOYwICnOcBw494CBfst4ur8TJXtp0N4oClrJeBht1+vG7L/xgk11P9+ H2y1dL0xea2b9jfQr7YpbkJeWBze59esLEZnA85ISq+2D2hCIIiUEKmdSJw3rUw6/loo eucSmDO9BnmrAqegl7lmVDjAgwjFT2QW8Je+/EwqiFd8eb/qTnFpcNjHHgZTbsy61IkO aPMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=VsW4w9Tidh8kQF/wOzdszRJTB9PdDmdFIqsfVlGud5k=; b=Blr03qQZKQ8wuR9TYauOWbUwLiBFUaNLM+PeOicEeNAcbfKK0Fd0HioNALKQbYhWjO 6JlXt2A73mlawDLxb0VqTrit9RgyILA6jHS7MMU0BRDeAs7eFav72a96ibosUxSgzN30 tAAkimdnU+WG24Y6uH1A8lNwjzSXM/IpIzfsq8pL6cN+KhE95cxbAhdO821josvJBNnE HxxJskHGB1xmQvqtTcyprHBAEWb/Z3XRYl29WJpvpAMJmUAwxoamHFiFZQugqp4NS9J1 OCGEE8glQT4ajNH6Y4HSkdeXrzaZWH62sv8HguJZTsqyN3rrtxLe1YZmoBJGUUECmJbl +naw== X-Gm-Message-State: AHQUAuZqd4JImA6qm5M9OtpW8jqhj4xk6PrNybUIiza5H8Piy8QIeVgD Prd+kuE7/kqaPk5cQUjIskKy8+ay X-Google-Smtp-Source: AHgI3IYw2a84v8avU20jClpDYZdXGMBAgRMuWAaIZjV3ziLNMG+cnPvQdIXm2lhSBGlS0JQDeJR1vA== X-Received: by 2002:a63:9c1a:: with SMTP id f26mr6619274pge.381.1549405253198; Tue, 05 Feb 2019 14:20:53 -0800 (PST) Received: from dtor-ws ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id r8sm4847051pgr.48.2019.02.05.14.20.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Feb 2019 14:20:52 -0800 (PST) Date: Tue, 5 Feb 2019 14:20:50 -0800 From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Sven Van Asbroeck , Jacek Anaszewski , linux-kernel@vger.kernel.org Subject: [PATCH] Input: cap11xx - switch to using set_brightness_blocking() Message-ID: <20190205222050.GA145676@dtor-ws> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) 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 Updating LED state requires access to regmap and therefore we may sleep, so we could not do that directly form set_brightness() method. Historically we used private work to adjust the brightness, but with the introduction of set_brightness_blocking() we no longer need it. As a bonus, not having our own work item means we do not have use-after-free issue as we neglected to cancel outstanding work on driver unbind. Reported-by: Sven Van Asbroeck Signed-off-by: Dmitry Torokhov Reviewed-by: Sven Van Asbroeck --- drivers/input/keyboard/cap11xx.c | 47 ++++++++++++++------------------ 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/drivers/input/keyboard/cap11xx.c b/drivers/input/keyboard/cap11xx.c index 312916f99597..c0baf323ddda 100644 --- a/drivers/input/keyboard/cap11xx.c +++ b/drivers/input/keyboard/cap11xx.c @@ -75,9 +75,8 @@ struct cap11xx_led { struct cap11xx_priv *priv; struct led_classdev cdev; - struct work_struct work; u32 reg; - enum led_brightness new_brightness; + enum led_brightness brightness; }; #endif @@ -233,30 +232,28 @@ static void cap11xx_input_close(struct input_dev *idev) } #ifdef CONFIG_LEDS_CLASS -static void cap11xx_led_work(struct work_struct *work) -{ - struct cap11xx_led *led = container_of(work, struct cap11xx_led, work); - struct cap11xx_priv *priv = led->priv; - int value = led->new_brightness; - - /* - * All LEDs share the same duty cycle as this is a HW limitation. - * Brightness levels per LED are either 0 (OFF) and 1 (ON). - */ - regmap_update_bits(priv->regmap, CAP11XX_REG_LED_OUTPUT_CONTROL, - BIT(led->reg), value ? BIT(led->reg) : 0); -} - -static void cap11xx_led_set(struct led_classdev *cdev, - enum led_brightness value) +static int cap11xx_led_set(struct led_classdev *cdev, + enum led_brightness value) { struct cap11xx_led *led = container_of(cdev, struct cap11xx_led, cdev); + struct cap11xx_priv *priv = led->priv; + int error = 0; + + if (led->brightness != value) { + /* + * All LEDs share the same duty cycle as this is a HW + * limitation. Brightness levels per LED are either + * 0 (OFF) and 1 (ON). + */ + error = regmap_update_bits(priv->regmap, + CAP11XX_REG_LED_OUTPUT_CONTROL, + BIT(led->reg), + value ? BIT(led->reg) : 0); + if (!error) + led->brightness = value; + } - if (led->new_brightness == value) - return; - - led->new_brightness = value; - schedule_work(&led->work); + return error; } static int cap11xx_init_leds(struct device *dev, @@ -299,7 +296,7 @@ static int cap11xx_init_leds(struct device *dev, led->cdev.default_trigger = of_get_property(child, "linux,default-trigger", NULL); led->cdev.flags = 0; - led->cdev.brightness_set = cap11xx_led_set; + led->cdev.brightness_set_blocking = cap11xx_led_set; led->cdev.max_brightness = 1; led->cdev.brightness = LED_OFF; @@ -312,8 +309,6 @@ static int cap11xx_init_leds(struct device *dev, led->reg = reg; led->priv = priv; - INIT_WORK(&led->work, cap11xx_led_work); - error = devm_led_classdev_register(dev, &led->cdev); if (error) { of_node_put(child);