From patchwork Wed May 17 20:55:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudip Mukherjee X-Patchwork-Id: 9731893 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 5CAB5600CC for ; Wed, 17 May 2017 20:55:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22F98287D6 for ; Wed, 17 May 2017 20:55:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 177D4287ED; Wed, 17 May 2017 20:55:22 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 7AAE7287D6 for ; Wed, 17 May 2017 20:55:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753250AbdEQUzU (ORCPT ); Wed, 17 May 2017 16:55:20 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:33843 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753906AbdEQUzT (ORCPT ); Wed, 17 May 2017 16:55:19 -0400 Received: by mail-wr0-f193.google.com with SMTP id 6so3557815wrb.1; Wed, 17 May 2017 13:55:13 -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=6D7KKQssnnp5GYUkHbPR0BchZL8zdNacurJp0VR06IM=; b=TRys9KQJZe3dnNNXEeEVEMAPfmJsY2Wmm8t2cnGSt5jqOqFmKOIrmlkcZtM1Pfsbm6 7YluM7GeyO9rYsSu1eOQf+Vf2i4kpYSTlymJlLCZRTUKqvKP/rRHu2wUoUpjFv1rJNWu HVTZkdzE/OhDFbCuF8X4TkKFuL82pJ7pqh0HO641X2QbIa1xz8a4/gaGcYb1hpszFQyZ Jx8QeYwiCvaIvDc0JjuDRubDP/rcXwNvf4hpgiiGC4LWpdClO3gSPuvubxIpT7QJshI5 S67mpwSDYhq1wdkKE8zzPYHIvst+w9DTs7H2wwaSMXutEHYOvT6Q+5JLYY4XTTEAXg6H X2bA== 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=6D7KKQssnnp5GYUkHbPR0BchZL8zdNacurJp0VR06IM=; b=YkNCcoJdwXZuJ5ujEI66i+N7Dp9LV+Emwie3r/WYwREXZvil/qameRdq8iBGk5paKU /K03PkK1fi2aB3W99BH8jNEeT/B645DHvAbW6hkUkOSbQFMc+MR+1rScIrcBr2pu1OiC iW8csov2OCbbmtkLBiu2To2dZ472nuP10X6PGol8y6jvMYJpfGT1AjR4nMdxvUyJUr6P 8axaFtWqZS5mm1fVAgi+1QlE4HN2KzBXM+a3mCiqoC6Z+0fwWKTkqpW+UPR6quWXeVVD lupnXWgykPk/Y9BJPcOc15M4ULWJKilbUrEMFCalHdC8K9RljxiXEiWpVHzLVHcnfpZR m1LQ== X-Gm-Message-State: AODbwcCs4Ki+Nmsd9cKbTAp1YrBdDbjprEEjiwZxVd8/geMJFDtiv6dk BSEKjaNdww6Lwg== X-Received: by 10.223.157.11 with SMTP id k11mr348803wre.71.1495054513072; Wed, 17 May 2017 13:55:13 -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 v138sm3037807wmv.4.2017.05.17.13.55.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 May 2017 13:55:12 -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 v5] backlight: report error on failure Date: Wed, 17 May 2017 21:55:07 +0100 Message-Id: <1495054507-9988-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. Acked-by: Daniel Thompson Signed-off-by: Sudip Mukherjee --- v5: dropped the ternary condition 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. drivers/video/backlight/backlight.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index 288318a..8049e76 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,16 @@ 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; + } else { + rc = count; } - rc = count; } mutex_unlock(&bd->ops_lock); @@ -176,8 +182,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);