From patchwork Tue Jan 25 23:25:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 12724359 X-Patchwork-Delegate: gustavo@embeddedor.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACE28C5DF62 for ; Tue, 25 Jan 2022 23:18:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234710AbiAYXSk (ORCPT ); Tue, 25 Jan 2022 18:18:40 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:36928 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234706AbiAYXSj (ORCPT ); Tue, 25 Jan 2022 18:18:39 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8244B61245; Tue, 25 Jan 2022 23:18:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65519C340E0; Tue, 25 Jan 2022 23:18:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643152718; bh=n1VEybndR/BWFpxIeiPPk6LEiEOujbaxi3aCa0daOV8=; h=Date:From:To:Cc:Subject:From; b=Mld1rJjAY78xN8cu5NzxFFchzV9a/lwE7wdYoBu6ssbzzZ8KbSx3CnWtnBCQ+X/xN mCb5LjTEdH5R78XdzxqYZCEBFEpsJtB6CNpfG185UBd3l88XYoaGF7nVnrZMCF4QXO azr0jLX6QMH9mGz7QcqUFz1Wo/Bbunv8fPSapv+xIsJugNa8iBe0VRZH6CJIj7WyZu kJQ51XcoyUoYJUpi9h/5ab4Uw/7COTAj8rplX/MqywdR7wH7s70sDNtYwA1d2TASOH 9hdDazjO3IPPMhO7iDhm+gb0DJLvKDZjwA5uTbPybWXrYPL4OlzrDla+acUpIqsvAP hySYIi3bM0mLg== Date: Tue, 25 Jan 2022 17:25:25 -0600 From: "Gustavo A. R. Silva" To: Ian Abbott , H Hartley Sweeten Cc: linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] comedi: das16: Use struct_size() helper in comedi_alloc_spriv() Message-ID: <20220125232525.GA80228@embeddedor> MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows. Also, address the following sparse warnings: drivers/comedi/drivers/das16.c:964:45: warning: using sizeof on a flexible structure drivers/comedi/drivers/das16.c:998:45: warning: using sizeof on a flexible structure Link: https://github.com/KSPP/linux/issues/174 Signed-off-by: Gustavo A. R. Silva Reviewed-by: Ian Abbott --- drivers/comedi/drivers/das16.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/comedi/drivers/das16.c b/drivers/comedi/drivers/das16.c index 937a69ce0977..728dc02156c8 100644 --- a/drivers/comedi/drivers/das16.c +++ b/drivers/comedi/drivers/das16.c @@ -961,7 +961,7 @@ static const struct comedi_lrange *das16_ai_range(struct comedi_device *dev, /* allocate single-range range table */ lrange = comedi_alloc_spriv(s, - sizeof(*lrange) + sizeof(*krange)); + struct_size(lrange, range, 1)); if (!lrange) return &range_unknown; @@ -995,7 +995,7 @@ static const struct comedi_lrange *das16_ao_range(struct comedi_device *dev, /* allocate single-range range table */ lrange = comedi_alloc_spriv(s, - sizeof(*lrange) + sizeof(*krange)); + struct_size(lrange, range, 1)); if (!lrange) return &range_unknown;