Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6018522ybc; Wed, 27 Nov 2019 13:30:24 -0800 (PST) X-Google-Smtp-Source: APXvYqztnrHPM3O7po/gOeH32bSx1j0w9kUiA9csAtRAdqb9x36Wn6jjJ4NNoBCmZws9rY6K/obw X-Received: by 2002:aa7:df8e:: with SMTP id b14mr34815305edy.59.1574890224192; Wed, 27 Nov 2019 13:30:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574890224; cv=none; d=google.com; s=arc-20160816; b=heTF/VcpbrqzAb4gVU9U0+BNfGayyXZfGAaB/D0vb3D2GSl4ZoVptOf8VeBxHIE4SD v0v4fLVqiHgGJsj2KZsfXHgFWoxh7TZ7MSglWEgVwmiObOLa8dFOOjgiwSzFsd3f/tIS Q1dHpk5o6gDyTlJmyh4is2I2+pr+F5ZLWXcZxM5xIaln5MGZg0cLMpCK4F+q0rwh/ojx e9a39IkPGXgS+f/6d2DrSaNIaZL6fNAPBbxeda4pTmaCrnFYWbVFfbw9HB06IeO2XvWH B32lASIP7E/u7XqlNaRn70m0eaHfjsTTqP8TEbUNr6YxBCeqvjm1kXcSQRGJoOfWzDTR tt8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uCY9Bg39yesPNMX74BwDzJIzenazJ5TBxu2lhrlJIGs=; b=ChA9Gx9KT58BEo4gshIQGKetaoN8rjUhJlP8uUrqLWk63RUy6E7Y1N0W83QwaqxFph 4IUhn/gUyGpsPTkCJ+DN7vsvFqe5l0CVAUt0i6lHJWvTRukOMYgGD3ToEJxP1Tyvki9o ad1bxrX05rX/paDta8Jy7cXc1LKT+yf40Se5pLlTSVEQDeyGOV0mClT98CaeXaLXXOWN H48Mzu+jYcLmRnbCl+PfyAZLMqDJMS/X6pRNCbuEMvXWOAv4ROzWQ3PI1U3gCeDNqK7Q mWpE1xSM5TDSjJ31u0l0toz9IRMFE4AfZMRnIygWX3+OaM7JyE0swoLBf8E9oog8YQgl KgmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="X3/pDK9K"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z12si10904340edx.47.2019.11.27.13.30.01; Wed, 27 Nov 2019 13:30:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="X3/pDK9K"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732022AbfK0V1l (ORCPT + 99 others); Wed, 27 Nov 2019 16:27:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:50782 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731399AbfK0U7S (ORCPT ); Wed, 27 Nov 2019 15:59:18 -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 1D32C2084B; Wed, 27 Nov 2019 20:59:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888357; bh=Mjp9Ayi7gHDEl4RyIz4743czz+ZO/l4kYbTirM1WaXM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X3/pDK9Kpqx3wrx7+biu/ygFnUgoqSC9RDrD6J2CA16K/yyI1eBuXL8OgsvqyDL22 0R9cpb8L2ytrK8VhEV3dBOGjuinDqo41nzd8h8HLFICTSJMNwTUtfsC+EDpVXf4lku uQc4t0GB7rXcrtlE1Htsh2x7lvC0x7U8MqhXoqpQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Duncan Laurie , Vadim Bendebury , Stefan Reinauer , Furquan Shaikh , Furquan Shaikh , Aaron Durbin , Justin TerAvest , Ross Zwisler , Guenter Roeck , Sasha Levin Subject: [PATCH 4.19 050/306] gsmi: Fix bug in append_to_eventlog sysfs handler Date: Wed, 27 Nov 2019 21:28:20 +0100 Message-Id: <20191127203118.448242319@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@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: Duncan Laurie [ Upstream commit 655603de68469adaff16842ac17a5aec9c9ce89b ] The sysfs handler should return the number of bytes consumed, which in the case of a successful write is the entire buffer. Also fix a bug where param.data_len was being set to (count - (2 * sizeof(u32))) instead of just (count - sizeof(u32)). The latter is correct because we skip over the leading u32 which is our param.type, but we were also incorrectly subtracting sizeof(u32) on the line where we were actually setting param.data_len: param.data_len = count - sizeof(u32); This meant that for our example event.kernel_software_watchdog with total length 10 bytes, param.data_len was just 2 prior to this change. To test, successfully append an event to the log with gsmi sysfs. This sample event is for a "Kernel Software Watchdog" > xxd -g 1 event.kernel_software_watchdog 0000000: 01 00 00 00 ad de 06 00 00 00 > cat event.kernel_software_watchdog > /sys/firmware/gsmi/append_to_eventlog > mosys eventlog list | tail -1 14 | 2012-06-25 10:14:14 | Kernl Event | Software Watchdog Signed-off-by: Duncan Laurie Reviewed-by: Vadim Bendebury Reviewed-by: Stefan Reinauer Signed-off-by: Furquan Shaikh Tested-by: Furquan Shaikh Reviewed-by: Aaron Durbin Reviewed-by: Justin TerAvest [zwisler: updated changelog for 2nd bug fix and upstream] Signed-off-by: Ross Zwisler Reviewed-by: Guenter Roeck Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/firmware/google/gsmi.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/google/gsmi.c b/drivers/firmware/google/gsmi.c index c8f169bf2e27d..62337be07afcb 100644 --- a/drivers/firmware/google/gsmi.c +++ b/drivers/firmware/google/gsmi.c @@ -480,11 +480,10 @@ static ssize_t eventlog_write(struct file *filp, struct kobject *kobj, if (count < sizeof(u32)) return -EINVAL; param.type = *(u32 *)buf; - count -= sizeof(u32); buf += sizeof(u32); /* The remaining buffer is the data payload */ - if (count > gsmi_dev.data_buf->length) + if ((count - sizeof(u32)) > gsmi_dev.data_buf->length) return -EINVAL; param.data_len = count - sizeof(u32); @@ -504,7 +503,7 @@ static ssize_t eventlog_write(struct file *filp, struct kobject *kobj, spin_unlock_irqrestore(&gsmi_dev.lock, flags); - return rc; + return (rc == 0) ? count : rc; } -- 2.20.1