Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp3189552pxb; Mon, 6 Sep 2021 14:58:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOtmT6OeDVRLrfiZsVuIeqfUa8KgRkeCb9x3OExYFjYphonDU5re+JZWxPj0UHq4Xk6EFz X-Received: by 2002:a05:6e02:1a6b:: with SMTP id w11mr9658849ilv.69.1630965518842; Mon, 06 Sep 2021 14:58:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630965518; cv=none; d=google.com; s=arc-20160816; b=DWl/sbW33KYMiWRi6cQCLaAFYZcFyyx3Xieiu/k7cAblKKJuA8rEO4dxNR60s0cc2s Puv9BWEnU4LJaufMyOgSMF5zz45psWdABJt2Pl3m3fa3NqIdoDCGoGujNQKDMGqPc+pz PdeuDF069AHegQlWfSA6V/Wtxun1S6j5KZRMKNhFhr0hRZGwePvhLhn4OtjxpsDSrwwL N1lwzGTw78sZqUmCFWz1QigtXHbVdmIYeXQP/FrU1wBXY3JnwXFBYH4icfh5ecVeVvXo RSQdPE6EoSj8RRJZ+eqE/CM/7KyVWRi/NzYhEdvCktbRq2jOYZZiPnTpYNjFykmIIzt5 Q+PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:dkim-signature:from; bh=Fxe4Nq3qWiNsClIYWaPluDuOAlGF0i7+75H4EqXg12Y=; b=DM/Ze5C/2EZ6vz63AxTz153b+nrsRhLsaTFswLWsImQFfkBzPR/CArFmw2rQ7Efs5H GA5ZF6tdOrmkWadEEg3jELgizj9Wrknr+8FiFmC6qIaT7L8BWssLdSmsuTxY/ezWrajT h6xUNVB9Gxb3e8osrkdkDe8NE4Q4PVoA15VNdhXp+D/rQQgKM4PyjBI41OVuXE173ucs yoLB1oS/mHLGMhGg7PnlBnohBEbpioUyp++IDZGw2oNFPmrO+lmwiqzLSR2ImY6i/72V 8JeTnWZR3AoRPuD9BGSk+xGvMd/9AiaSzTUavloSTiOygGkJexEG2BWJbxWKsqyRLe/p oApA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@weissschuh.net header.s=mail header.b=shQLHPvH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g63si5036578jab.37.2021.09.06.14.58.27; Mon, 06 Sep 2021 14:58:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@weissschuh.net header.s=mail header.b=shQLHPvH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233404AbhIFV6b (ORCPT + 99 others); Mon, 6 Sep 2021 17:58:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229766AbhIFV6b (ORCPT ); Mon, 6 Sep 2021 17:58:31 -0400 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74626C061575; Mon, 6 Sep 2021 14:57:23 -0700 (PDT) From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=weissschuh.net; s=mail; t=1630965441; bh=TBejuk5tqxeDF6kzvgEoVLlD9PzQKnYZHfHp2go1+m0=; h=From:To:Cc:Subject:Date:From; b=shQLHPvHG8+XyfIILO61kyyNG/BROBofAliqcMYmkCUaLfm8HZHAJviNKtZ7hMEmy DHiJe+9HFHypMP2UtGvEWf+3kxmPh/PNqAGqtVGOPpr7UbLPjKVJOobRUqoJEKMTVS 05/jvbADBFSRMZGQdtRjveq4E4vXVYzHIUKr1L0U= To: Lee Jones , Daniel Thompson , Jingoo Han , dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org Cc: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , linux-kernel@vger.kernel.org Subject: [PATCH] backlight: propagate errors from get_brightness() Date: Mon, 6 Sep 2021 23:55:25 +0200 Message-Id: <20210906215525.15418-1-linux@weissschuh.net> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org backlight.h documents "struct backlight_ops->get_brightness()" to return a negative errno on failure. So far these errors have not been handled in the backlight core. This leads to negative values being exposed through sysfs although only positive values are documented to be reported. Signed-off-by: Thomas Weißschuh --- drivers/video/backlight/backlight.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index 537fe1b376ad..d681962f8509 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c @@ -292,10 +292,13 @@ static ssize_t actual_brightness_show(struct device *dev, struct backlight_device *bd = to_backlight_device(dev); mutex_lock(&bd->ops_lock); - if (bd->ops && bd->ops->get_brightness) - rc = sprintf(buf, "%d\n", bd->ops->get_brightness(bd)); - else + if (bd->ops && bd->ops->get_brightness) { + rc = bd->ops->get_brightness(bd); + if (rc >= 0) + rc = sprintf(buf, "%d\n", rc); + } else { rc = sprintf(buf, "%d\n", bd->props.brightness); + } mutex_unlock(&bd->ops_lock); return rc; @@ -381,9 +384,18 @@ ATTRIBUTE_GROUPS(bl_device); void backlight_force_update(struct backlight_device *bd, enum backlight_update_reason reason) { + int brightness; + mutex_lock(&bd->ops_lock); - if (bd->ops && bd->ops->get_brightness) - bd->props.brightness = bd->ops->get_brightness(bd); + if (bd->ops && bd->ops->get_brightness) { + brightness = bd->ops->get_brightness(bd); + if (brightness >= 0) + bd->props.brightness = brightness; + else + dev_warn(&bd->dev, + "Could not update brightness from device: errno = %d", + -brightness); + } mutex_unlock(&bd->ops_lock); backlight_generate_event(bd, reason); } base-commit: 79fad92f2e596f5a8dd085788a24f540263ef887 -- 2.33.0