Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp252302rdf; Tue, 21 Nov 2023 01:24:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHvUF99GyeUc64yKgyZWcmDZcwWvun2vUleUvAeEakxi5Y62sDNAvE9VCLe30XOQP3bTFaf X-Received: by 2002:a05:6a00:a0f:b0:6be:7ee:9900 with SMTP id p15-20020a056a000a0f00b006be07ee9900mr9041424pfh.8.1700558669278; Tue, 21 Nov 2023 01:24:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700558669; cv=none; d=google.com; s=arc-20160816; b=oxUDsw0ydukiFEMtFP9hCb5UlzaHVcRm2ScmRmkYWzeou621tyiIucR2sHkVp1veqG CJq1JzZtuJVlEdH7K9ouqGtE30RKur2Ra6/NhBoIHJkTzPMSxToVvr2EZ1JS9kYSKDY0 kr4oFz6z4FJqS37xKL51kychk45JXzmbirgi4u5f8ajPOO2BOfTC00NJ5mn+mIlbziif xn99yp72ci8gpBbuDYShLcXamZleAfYaS9evv3TuXlIFV43oE7Vzy5+N0I8eVCQhiQ2n dFG0xhX4gHXxJhkNj6rWUdA1eqsa6FMWEVTMXpDPnKpc93u0rmSisEd8iPSZE43cDHDN Hb5A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lcx3HgUGMnG0vRpmKR86ed1JcihRMxKNfjPdR0bGPqY=; fh=0ObAmf4Mixw588hCbiOg2Smfm69nKze5F9tkIjSh2bI=; b=PhlJYIxOuSt18YRE7fq6cHp9xcNBK+qCGk5RfuRaz3iL/Gg4wt2vnUbDXmf4eZOvG4 MWWGvCT0UZUcG1l0LkCvdgBvSadvG7HD45ssJqTsVwy4bEUCcP6TyfoO8wJRQ3HpemIY vzfq0op2gNzoUULDzYx9r+2QQxRMmdFZ+K+0lS56anWivh/RRPuMq1Fu/epbcBAD/jHK tndf7tVuI4xB+TpOQH8h0A66feCwZ2xYv2zsLbJBPQMC/DLkqUm7emeK670joeMy26Hw Rzjz/Umpw1MIAfD6goMURyMDNQt7DJwM27mweQ67jiD9H9fcbXbLcA1XnHh7RkuiiCpr lVEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ljq1V0RC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id k15-20020aa788cf000000b00690fe0f6e0dsi10507943pff.68.2023.11.21.01.24.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 01:24:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ljq1V0RC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 185F080E73F3; Tue, 21 Nov 2023 01:24:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233176AbjKUJX6 (ORCPT + 99 others); Tue, 21 Nov 2023 04:23:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233597AbjKUJXl (ORCPT ); Tue, 21 Nov 2023 04:23:41 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 263B510C0 for ; Tue, 21 Nov 2023 01:23:23 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50BFFC433BD; Tue, 21 Nov 2023 09:23:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700558603; bh=+5n2mUpG4q3myzhvyd7KfFL/hxg0CFLJ/PmuTSTaY6A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ljq1V0RC2KP6ws3XfIFi2ZR28B0v5Bfu38nZAOFsLytKLElqcxHwreJJQLxWZ+fri mWSMDDvPs64Aof9bEcPnM6TRuWBTy6YOzLt5yZUy3MqiUdh74Iyne4CQryja0MK6DC WW+HJ6KY+9qIRLpdDaiBqHyNQgxwzYbL+77WrZM2DtKVU824khjepG0Sfqt/9BCMb6 Up2caehfFcZlTOCyI9KomPdNrrUHfY9h8wDItDtRiHa/2GIAw5UGnOtwrcUJh4Q1+j u/WCFpblEnv7exzQktl2l7+Y04/Xlv/eIRTeaQsfQh8IoFf1+L9BdNJg/d1Pcljsn/ +rohHZM+ihVlg== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" , linuxppc-dev@lists.ozlabs.org Subject: [PATCH 11/17] tty: hvc_console: use flexible array for outbuf Date: Tue, 21 Nov 2023 10:22:52 +0100 Message-ID: <20231121092258.9334-12-jirislaby@kernel.org> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20231121092258.9334-1-jirislaby@kernel.org> References: <20231121092258.9334-1-jirislaby@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 01:24:19 -0800 (PST) This means: * move outbuf to the end of struct hvc_struct and convert from pointer to flexible array (the structure is smaller now) * use struct_size() at the allocation site * align outbuf in the struct instead of ALIGN() at kzalloc() And apart from the above, use u8 instead of char (which are the same thanks to -funsigned-char). The former is now preferred over the latter. It makes the code easier to understand. Signed-off-by: Jiri Slaby (SUSE) Cc: linuxppc-dev@lists.ozlabs.org --- drivers/tty/hvc/hvc_console.c | 4 +--- drivers/tty/hvc/hvc_console.h | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c index 959fae54ca39..93b613e1f176 100644 --- a/drivers/tty/hvc/hvc_console.c +++ b/drivers/tty/hvc/hvc_console.c @@ -922,8 +922,7 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data, return ERR_PTR(err); } - hp = kzalloc(ALIGN(sizeof(*hp), sizeof(long)) + outbuf_size, - GFP_KERNEL); + hp = kzalloc(struct_size(hp, outbuf, outbuf_size), GFP_KERNEL); if (!hp) return ERR_PTR(-ENOMEM); @@ -931,7 +930,6 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data, hp->data = data; hp->ops = ops; hp->outbuf_size = outbuf_size; - hp->outbuf = &((char *)hp)[ALIGN(sizeof(*hp), sizeof(long))]; tty_port_init(&hp->port); hp->port.ops = &hvc_port_ops; diff --git a/drivers/tty/hvc/hvc_console.h b/drivers/tty/hvc/hvc_console.h index 9668f821db01..b718714bf399 100644 --- a/drivers/tty/hvc/hvc_console.h +++ b/drivers/tty/hvc/hvc_console.h @@ -37,7 +37,6 @@ struct hvc_struct { spinlock_t lock; int index; int do_wakeup; - char *outbuf; int outbuf_size; int n_outbuf; uint32_t vtermno; @@ -48,6 +47,7 @@ struct hvc_struct { struct work_struct tty_resize; struct list_head next; unsigned long flags; + u8 outbuf[] __aligned(sizeof(long)); }; /* implemented by a low level driver */ -- 2.42.1