From patchwork Thu May 11 21:36:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudip Mukherjee X-Patchwork-Id: 9723187 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 46BCA60236 for ; Thu, 11 May 2017 21:37:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E98128701 for ; Thu, 11 May 2017 21:37:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 326552872A; Thu, 11 May 2017 21:37:09 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 82F0828701 for ; Thu, 11 May 2017 21:37:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755866AbdEKVhI (ORCPT ); Thu, 11 May 2017 17:37:08 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:33189 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755606AbdEKVhH (ORCPT ); Thu, 11 May 2017 17:37:07 -0400 Received: by mail-wm0-f67.google.com with SMTP id y10so9796333wmh.0; Thu, 11 May 2017 14:37:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=BCqWMn4ZTvIloZ0WuK9pmaY3eWpbdOlgH13Q7uF/Sag=; b=oFj0oi0adJfZqdXEYKRT2U96AD1ogCbyV7E0u5QlXqgDyiiVhzre4ldPpdaPZT6AnB 3EGCk05fIl1YzuXALX16fglNTbqkqJ0EjDxlYRDMcqb5CGbIRlFveWUPMgDRZAhhdreY a6d27KdiWKd+l6PbUAq3vjQWQ5YLMWEbKnTS7Yt4K+zNQhqZM1jH5GatjLIY56wjzHX8 e7yIcIfkj6E/wpRZMjuLHJL7mzDstWQrJ6wqnA76r+YKyiAzSN2yvpkKk3MA1DHeTvlO Rpt0Q4U/+GOGPYR8Nlq1DFXWo4U+mliZ5G4JInFo5aK1MugRWjTeRjDTrJNIq08zKn36 SCsQ== 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; bh=BCqWMn4ZTvIloZ0WuK9pmaY3eWpbdOlgH13Q7uF/Sag=; b=NSt13HleuQfT2TebDv13H/rLaQXABQqFSCrXacIQTZlQhRSQPolNDu3k4X5drI8Nhh J+twrccAViPRfcAkUv8LhXB346G7f23/qN5NKhOFyUzf4RP5WDdyS9/JtVts/0dKKf51 HDrXcx4s+/YuZ2oY3/c5JeQ65jvQtVqKLlZOYHtsdsZpaB6Yfq2+bQ00vWEEfcey5pkD s2S46O0hzcKMSsq4oGz4854xZhO/nj4iBot/HeLGBYO31bTNa/xcq9KXgEb1HICBPzux Tm6XmjHix1UXMiyVaZxj1MHcrqDUfnFOoOpgRWux9V+GdO2QWh2zHWBMCDMhPBcrLaPK /pHg== X-Gm-Message-State: AODbwcD22KZmN8nKilHlkrl6OquqZSlnaOCRCz+CNuY6jlyo8RfFHLM0 ae7oRx2eyEmpZg== X-Received: by 10.28.142.4 with SMTP id q4mr414261wmd.112.1494538625662; Thu, 11 May 2017 14:37:05 -0700 (PDT) Received: from localhost.localdomain (cpc101300-bagu16-2-0-cust362.1-3.cable.virginm.net. [86.21.41.107]) by smtp.gmail.com with ESMTPSA id a197sm1354671wma.1.2017.05.11.14.37.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 May 2017 14:37:05 -0700 (PDT) From: Sudip Mukherjee To: Lee Jones , Daniel Thompson , Jingoo Han , Bartlomiej Zolnierkiewicz Cc: linux-kernel@vger.kernel.org, linux-fbdev@vger.kernel.org, Andy Shevchenko , Sudip Mukherjee Subject: [PATCH v4] backlight: report error on failure Date: Thu, 11 May 2017 22:36:59 +0100 Message-Id: <1494538619-3595-1-git-send-email-sudipm.mukherjee@gmail.com> X-Mailer: git-send-email 1.9.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 It is possible to update the backlight power and the brightness using the sysfs and on writing it either returns the count or if the callback function does not exist then returns the error code 'ENXIO'. We have a situation where the userspace client is writing to the sysfs to update the power and since the callback function exists the client receives the return value as count and considers the operation to be successful. That is correct as the write to the sysfs was successful. But there is no way to know if the actual operation was done or not. backlight_update_status() returns the error code if it fails. Pass that to the userspace client who is trying to update the power so that the client knows that the operation failed. Signed-off-by: Sudip Mukherjee Acked-by: Daniel Thompson Acked-by: Daniel Thompson --- v4: ABI comment removed from commit message v3: remove rc = 0, and update rc with count in else condition. v2: update power with old value on failure. Copy-pasting from the last patch conversation: The problem that prompted me to send this patch is the current project that I am working on now. And we faced this there. The userspace code is writing to the sysfs node to poweron the backlight and reported success. But sometimes we noticed that backlight was not actally powered on. And that lead me to check the code and noticed that it is swallowing all the errors. drivers/video/backlight/backlight.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index 288318a..0289107 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c @@ -134,7 +134,7 @@ static ssize_t bl_power_store(struct device *dev, struct device_attribute *attr, { int rc; struct backlight_device *bd = to_backlight_device(dev); - unsigned long power; + unsigned long power, old_power; rc = kstrtoul(buf, 0, &power); if (rc) @@ -145,10 +145,15 @@ static ssize_t bl_power_store(struct device *dev, struct device_attribute *attr, if (bd->ops) { pr_debug("set power to %lu\n", power); if (bd->props.power != power) { + old_power = bd->props.power; bd->props.power = power; - backlight_update_status(bd); + rc = backlight_update_status(bd); + if (rc) + bd->props.power = old_power; + } else { + rc = count; } - rc = count; + rc = rc ? rc : count; } mutex_unlock(&bd->ops_lock); @@ -176,8 +181,7 @@ int backlight_device_set_brightness(struct backlight_device *bd, else { pr_debug("set brightness to %lu\n", brightness); bd->props.brightness = brightness; - backlight_update_status(bd); - rc = 0; + rc = backlight_update_status(bd); } } mutex_unlock(&bd->ops_lock);