From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6646C432C0 for ; Wed, 27 Nov 2019 20:35:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A8E3D215B2 for ; Wed, 27 Nov 2019 20:35:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574886931; bh=GQdssR5vvChor4Ev4t2/5349FPN4oSbrjLFcBctu+Y0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=CO8FAqZ3aj4hdSpZUGmZaJkwRZg1QtT4X55l8rXnD4R3vncYKAh6j34fiS4hcM85N B9nCchnoDz/xCm2tiJAlp7xYwViR+KfO2ROUrwtVe0RvQ2j8fDh8T6x29WMmdAsUGP cV8KEt9gu0xbmUwUApncmaP4hbgeIYnzLUsdXYi0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727891AbfK0Ufa (ORCPT ); Wed, 27 Nov 2019 15:35:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:36666 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727848AbfK0Uf0 (ORCPT ); Wed, 27 Nov 2019 15:35:26 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E8CC02154A; Wed, 27 Nov 2019 20:35:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574886926; bh=GQdssR5vvChor4Ev4t2/5349FPN4oSbrjLFcBctu+Y0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NIOJToz7rGmbbp5VMWQpGixnUp6+em0zROVAqfQDNAjYx8qIVpB4E0it5+1BevXRH Ww+PFTOVc/aDQ7y8oZo38C0X2DLGCTOPkwmRrmdfmjwZhmGcbpFDkcUJsPdbpVgwEC iW2NAxcJWer/fEn5medo9dd/Stb3oNhJWir7gnjg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mattias Jacobsson <2pi@mok.nu>, Sasha Levin Subject: [PATCH 4.4 046/132] USB: misc: appledisplay: fix backlight update_status return code Date: Wed, 27 Nov 2019 21:30:37 +0100 Message-Id: <20191127202942.227536708@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127202857.270233486@linuxfoundation.org> References: <20191127202857.270233486@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mattias Jacobsson <2pi@mok.nu> [ Upstream commit 090158555ff8d194a98616034100b16697dd80d0 ] Upon success the update_status handler returns a positive number corresponding to the number of bytes transferred by usb_control_msg. However the return code of the update_status handler should indicate if an error occurred(negative) or how many bytes of the user's input to sysfs that was consumed. Return code zero indicates all bytes were consumed. The bug can for example result in the update_status handler being called twice, the second time with only the "unconsumed" part of the user's input to sysfs. Effectively setting an incorrect brightness. Change the update_status handler to return zero for all successful transactions and forward usb_control_msg's error code upon failure. Signed-off-by: Mattias Jacobsson <2pi@mok.nu> Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/misc/appledisplay.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c index 993f4da065c3a..dabd1077d03c4 100644 --- a/drivers/usb/misc/appledisplay.c +++ b/drivers/usb/misc/appledisplay.c @@ -161,8 +161,11 @@ static int appledisplay_bl_update_status(struct backlight_device *bd) pdata->msgdata, 2, ACD_USB_TIMEOUT); mutex_unlock(&pdata->sysfslock); - - return retval; + + if (retval < 0) + return retval; + else + return 0; } static int appledisplay_bl_get_brightness(struct backlight_device *bd) -- 2.20.1