Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp3727626pxb; Tue, 7 Sep 2021 06:24:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwK32OfPU9qLaQZlrIE3REUYCUb8upo9ERg31zU3udWH/aWBRUjHB/DeRaV6i7QFWADkXD5 X-Received: by 2002:a17:906:7097:: with SMTP id b23mr3192672ejk.270.1631021060546; Tue, 07 Sep 2021 06:24:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631021060; cv=none; d=google.com; s=arc-20160816; b=d7nzx4blB/439JGJf3Q4Vs0/CG14+K38qm6dtYTp7RinQvIsJJ/Jpnlp1UsrPPLKxi Nah6+qewZHDzEridTjcRjQh5HzTT7/o4npoN3pdd9IIgtwonK1UP1EHI3xPONgYkgpYN QfpnvbxDjfEnHfKUPQUHrMvN722Kyp+VLhxBimnOqUY2YlTAOc9xm1tk7zAvXSZdG9uS YNdQwllYlqZjntS8pQXK6Ckubf/NpM3l2zDvY0qRP+egsfog/hn3hD0dsta8RoY3aYoL jO3FA7kTf6T01QWE9iJvUeb9Qx8YjXFofYmPn/b+IyyztclBnIGKI6GMSwX9jNxIHRc1 OWwg== 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=/hxb9tjcgpwXWTOkaibwhY/Gwq5dPX9oW12Q+OpNKYI=; b=J6ckbZirgGE5VkNG7cc9xlgFpxgmQBpTdhVWHnCzor+mSw4GYOv3gmOXMgAizZMg9q DpuYUK9Pn+C4clUV8v1ERsytPC63/DraVPdYb0B2h455tccZfz0whz+gzUhUYVcrW7UD zMvfOg01kPh+7V9TVuXHM4ecH3If31XZgbjn0RY0q2a85SxhiP+MXrPdjUk6P9ML4qvk WfryroWz1r1zHjM/yWsYQfhZzwvRavv37Aa19xwgHJPR2roVd7UU2qIPxDjkt7g7BqvI e8QnNaqX5MDLjLWbhBltNdUQPwP0EYp3QArGGO6aqzvbUENzqVWU2I7kq5QKmVwU8fWQ YKcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@weissschuh.net header.s=mail header.b=IooRD0Vl; 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 ji22si10897881ejc.361.2021.09.07.06.23.56; Tue, 07 Sep 2021 06:24:20 -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=IooRD0Vl; 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 S1344367AbhIGMtI (ORCPT + 99 others); Tue, 7 Sep 2021 08:49:08 -0400 Received: from todd.t-8ch.de ([159.69.126.157]:39879 "EHLO todd.t-8ch.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231600AbhIGMtH (ORCPT ); Tue, 7 Sep 2021 08:49:07 -0400 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=weissschuh.net; s=mail; t=1631018878; bh=ATKYi2Vk5p0hBeuPNHEODB9n/mjvnxJq3rBPTJFZlp0=; h=From:To:Cc:Subject:Date:From; b=IooRD0Vl+15Z32+h4hNQYZl9xacLWEALyLzlP1IV3rSc3BA5DGwm9dyDsQP4+qvxv 8CDNM4tcj5LCSs/cslgzcxtYRh2FCtt3yxUtUD4/rZNyJfHcjH2zrQyvB2lxxhyJjv N8AcFOtaiaHs3r8Rjm2wZIxWm2JCbFZXc3kiFgfo= 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 v2] backlight: propagate errors from get_brightness() Date: Tue, 7 Sep 2021 14:47:51 +0200 Message-Id: <20210907124751.6404-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 --- v1: https://lore.kernel.org/dri-devel/20210906215525.15418-1-linux@weissschuh.net/ v1 -> v2: * use dev_err() instead of dev_warn() (Daniel Thompson) * Finish logging format string with newline (Daniel Thompson) * Log errno via dedicated error pointer format (Daniel Thompson) 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..4658cfb75aa2 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_err(&bd->dev, + "Could not update brightness from device: %pe\n", + ERR_PTR(brightness)); + } mutex_unlock(&bd->ops_lock); backlight_generate_event(bd, reason); } base-commit: 79fad92f2e596f5a8dd085788a24f540263ef887 -- 2.33.0