Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1938876ybv; Fri, 14 Feb 2020 08:33:09 -0800 (PST) X-Google-Smtp-Source: APXvYqzWLg8OqGZcv+V9fxiUq4BAqbkrr/kWmKnIuB94dirquWjZTVbVyz2+aad3Z8bfn3Z7udCn X-Received: by 2002:aca:3017:: with SMTP id w23mr2381511oiw.152.1581697989558; Fri, 14 Feb 2020 08:33:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581697989; cv=none; d=google.com; s=arc-20160816; b=vTETg+vRm1H8SnIL43jR9B/25YG4JSoJLl2a+xhRD0iNHVSajN3GpbDOMenhPSNxmH nUOxo8k3xweTJYMATye2F+XSZnoYA7QdDSpz8g8xxCRyUVUnYjZOTqJPtoujfB/osS01 ieL18qWTic8CGfizuJfhvxi9lONv9HaLuyEx1lQZzu2yVigfzvRqO1InYpBMDY42+2iO JcJOp/fGmK2yqTNKoWqKFw+WXe6klI85dpevx3B1Xkju01tHgU9dZCzaXXokQc+mf35z 7WKoWMFbxJr4PSgqXgpUka1PTkhjbMaA/QFJwYerI+l/954iihO869FibejHhHebdE95 qOmg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GNV4bU/d5C2WvACbEiclJjvUIAMhNPbfBec8QYFX4JA=; b=eBeM0FwQ2OMxHSbTNp0ToMek/bCdeIWSrwOnIekNfv5OBEovNQEU9X+hf5wkem89yV l0zhoFyPORv7GN5hhbwLOu5Ez5GFAVjQ+FoOds9CzPRtfbi6/1Nto+eUIbjJb8PAAUKN 4kNFOeuuU9Yj7EyPfYlqGeVj1eNk6F8Rql28Cp91DJ1WZC/WwiXmM9KU4p8xNsKmlgAF c5eXY+Ra71VR83wojE0Edp3HRqE1vLxpbqEJEWBIsY+O4WsI8nJ9ga5Z9/OhP3Et3VgK RrhIceQexepcbBcSWMyKVAbxI0/El3zc7FL4E/taTgz+jVeOlFKlqYhbk1zg7KPwQxOs jEmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dPsdEWCD; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j18si2885436oii.42.2020.02.14.08.32.57; Fri, 14 Feb 2020 08:33:09 -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=dPsdEWCD; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406252AbgBNQZz (ORCPT + 99 others); Fri, 14 Feb 2020 11:25:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:60294 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405712AbgBNQXq (ORCPT ); Fri, 14 Feb 2020 11:23:46 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DCF8D24780; Fri, 14 Feb 2020 16:23:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581697426; bh=oJIxZBnIPTrvFZMJWGftWgbdI8DB2FTc8wGJBaTBGP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dPsdEWCDBllBI/rERYFjoOmRkPVh3hcmyi8s5/D5z7C3jXpYY2NIbMh7IdSqeHXS3 GnwI7m5GKUs2XRwy1Z/c1GlWzRVjZgnmcXiDHo8bDffWb+3VFPtW2ZdaR77krQeJjS IxFybGyCrA2eTpwswHbed51PHIlEbF/oJWtFwz9c= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Gustavo A. R. Silva" , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL 4.9 115/141] char: hpet: Use flexible-array member Date: Fri, 14 Feb 2020 11:20:55 -0500 Message-Id: <20200214162122.19794-115-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200214162122.19794-1-sashal@kernel.org> References: <20200214162122.19794-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Gustavo A. R. Silva" [ Upstream commit 987f028b8637cfa7658aa456ae73f8f21a7a7f6f ] Old code in the kernel uses 1-byte and 0-byte arrays to indicate the presence of a "variable length array": struct something { int length; u8 data[1]; }; struct something *instance; instance = kmalloc(sizeof(*instance) + size, GFP_KERNEL); instance->length = size; memcpy(instance->data, source, size); There is also 0-byte arrays. Both cases pose confusion for things like sizeof(), CONFIG_FORTIFY_SOURCE, etc.[1] Instead, the preferred mechanism to declare variable-length types such as the one above is a flexible array member[2] which need to be the last member of a structure and empty-sized: struct something { int stuff; u8 data[]; }; Also, by making use of the mechanism above, we will get a compiler warning in case the flexible array does not occur last in the structure, which will help us prevent some kind of undefined behavior bugs from being unadvertenly introduced[3] to the codebase from now on. [1] https://github.com/KSPP/linux/issues/21 [2] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour") Signed-off-by: Gustavo A. R. Silva Link: https://lore.kernel.org/r/20200120235326.GA29231@embeddedor.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/char/hpet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c index bedfd2412ec19..abbfc147980db 100644 --- a/drivers/char/hpet.c +++ b/drivers/char/hpet.c @@ -112,7 +112,7 @@ struct hpets { unsigned long hp_delta; unsigned int hp_ntimer; unsigned int hp_which; - struct hpet_dev hp_dev[1]; + struct hpet_dev hp_dev[]; }; static struct hpets *hpets; -- 2.20.1