From patchwork Sat May 6 18:00:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudip Mukherjee X-Patchwork-Id: 9715079 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 EAB1260387 for ; Sat, 6 May 2017 18:00:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E20B428616 for ; Sat, 6 May 2017 18:00:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D58BD28622; Sat, 6 May 2017 18:00:30 +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 4983E28616 for ; Sat, 6 May 2017 18:00:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752570AbdEFSA0 (ORCPT ); Sat, 6 May 2017 14:00:26 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:34093 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752508AbdEFSAZ (ORCPT ); Sat, 6 May 2017 14:00:25 -0400 Received: by mail-wm0-f68.google.com with SMTP id z129so7138894wmb.1; Sat, 06 May 2017 11:00:24 -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=zH8B6EPoFTsxKJTZQCTKqwi/pooc6LmGnS1dassaud0=; b=Pq45udFF7KFnn5ZUrxFtD1AR8ZJWRLvPcFH8BerFZdR+nKe4r2/bl6raa6lRrPgIaP 8xCGttSTwEpWVn7BeK8OEHB0kverIoXB9wqNS5TV4uh0+HGeTx+hNheDvBaiHRIK59vp iG2MgQJa2TdskwBDBzzGSW9oMu3IhVmTyaL9vT32wG+sUmptOgcis/1/8bGcRHJwJZjZ m14YjSocuc503iswKkYK5kqR7eWnc3F/KDgRAXaSULNftozDSEkeO5S40c4SkmS19X7R r6qymMY9qHTOVVTi6givRcp5uJa3KZHTD/1ETM0fAYJeJNF2WIZfomowbVFVTEWkLvWU UnNw== 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=zH8B6EPoFTsxKJTZQCTKqwi/pooc6LmGnS1dassaud0=; b=lO2qbspWki3ZHDXpM3ceCLb+B2yz/oAvZmnjzv1OhFw3X1e0YVAippjYeTElL/bkPT jGXrNJr8JK2SBRt9Txu3eRwbegspWio5etHk81yL7KWJmd90189qaF6dbcVSllzMkqre aKRR/1zhryQXFdnVsqsmaPFrYjmsN8VQR3DbzPDZZS1hdsA5pelOSJbWndrEqAEbl/Aj ABcToIAoE82oxY9gABiJwzZEyyROjPjvrJAx2j5mp8PaTvGqDd2cfHbaYVHSIwE54SK+ u1zafn+iv8EyVQ3YNyGr44JwqPRhVm22uJ6ikrrawDxDnWQ8Biy35piC1pP+Trkf040d s7Jg== X-Gm-Message-State: AODbwcBbqq7ZMbY266K7BMKEn/SKD/592SZhekQNUv1KUeuUb2ujWOx9 DoiRrqCZ6Vax0Q== X-Received: by 10.28.68.195 with SMTP id r186mr5798291wma.22.1494093618724; Sat, 06 May 2017 11:00:18 -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 w18sm7548382wra.34.2017.05.06.11.00.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 06 May 2017 11:00:18 -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 v3] backlight: report error on failure Date: Sat, 6 May 2017 19:00:10 +0100 Message-Id: <1494093610-5561-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. This is not a change of ABI as the userspace expects an error of ENXIO, after this patch the range of errors that are returned to the userspace will increase. Signed-off-by: Sudip Mukherjee --- 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);