Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp40305lql; Sun, 10 Mar 2024 12:42:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWYh6nzlqxidBVjwLz6JydF5vRHSOCBpb9By3bd3JAHVCRWUaeoCj5M51l/Rt0YbrgkK+I32y+c5wiqvzBSUonzYNgr3LmAjM246Pz0xQ== X-Google-Smtp-Source: AGHT+IGEWwJGyL99FPyba1+n8ESi0PyWuw0NoBahPqRpHWAQbcAu9WgLdowJW8+ZrT68Nt0SEU8x X-Received: by 2002:a05:6870:ec91:b0:221:bf42:d019 with SMTP id eo17-20020a056870ec9100b00221bf42d019mr4098961oab.12.1710099736516; Sun, 10 Mar 2024 12:42:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710099736; cv=pass; d=google.com; s=arc-20160816; b=UH7uThPPqk/EeJOVmmfc2duIqIwkwX84uaOg6/vp3u6YgbSMzbp8THq4sjKVEuptI6 AOOaL1kHb6K3p4+ZtWSzR3TBfCgumkF5PoNNad5Na9agbvaYyih4SH2zV89ZhryPI4GU T7oE6ThVorogfJcuzepxokeaZwkGskv1px0068yHRq7Z80eNXF0VtnO2Y5HJJiWQIFuQ vbU47hri3PntncuCFs5SpadZvQPr60LnJchZLWtHP/mxp45flXqwhF1+I4RkIrDYoLYa t0fS9KtEDXsuYEpQT3RCLzY9ztjbfwSAPGwnG9g6nsdTqjavPMpgASU1ln+xLauY7idZ ahnA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:dkim-signature:date; bh=Cb7OKsY7pJ9Te/hhWi0i7nqCpNr5gLsM0TXwe5MbJsI=; fh=R92vWM/KAryU3oM/YarkKqcbft0IfE3jAWkpBydS0sc=; b=SXnP51uSh5T8lrl88BKyc0tYPI03ods17n+U2xXDd8LTb+KKS/Uur8Bn1ATltXQQNp mWV3FzavF+W/uzd3i0/MkW08dSGOOVsfggqsDYylMZ9GxFsOw4lLmYgQDieez07G6456 TN9lFv348lKW8yhf19MGt/ifewQaQOGPuyWP1y8C50Y1MDVFPh6/r2QvTGqEpoPgfkUw ZUU+cx7NwHsoMDuC4kHQF3LHF2PNRZnvPF56zAxBCWlivlXdAPHG34lyIC28cW4uBQFt 5Rmy7eRyj8iDGd/mIIFXrdO7Uxl5AJUipYNS9XuKlgB5/Cv4rkks6yjvR1NnRWubBn7V Wp/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=eSHxJm9j; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-98314-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98314-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id m21-20020a05620a215500b007884e34d677si3876530qkm.695.2024.03.10.12.42.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Mar 2024 12:42:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-98314-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=eSHxJm9j; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-98314-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98314-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 379421C209F9 for ; Sun, 10 Mar 2024 19:42:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 935F13A1AC; Sun, 10 Mar 2024 19:42:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="eSHxJm9j" Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7256039846 for ; Sun, 10 Mar 2024 19:42:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710099730; cv=none; b=vGMpzYciWBA/Auen+PxSm8BxCzdzITpLzTqVRSMb9CZy9gnpMn2t+5wlKWj5gq0J6XOJB3W1AFPN8KTyQOLWHV1mKQaXhkusm+zt6IKxujUOzYNqxIvbQbEOQU+lkA93W2q9HyzqeF+t+9P9ziHUR3RYMeIkEvmm3FEAkyf/Co0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710099730; c=relaxed/simple; bh=xXfTV4GI3xnP2k8SPtzObSqxaymakeQpPF3auXEnEwA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UTOdBsG/TaqC+15aY4Id1tQn5In9vm/sR3841dp1TEMNAdls9PUtOqy5EscYKHzcxJL5Y5aYMgehnEOU4eFaWx8eSgzZE79aCWkEfx1MEFIRhZchUNoPcmfD78KOx6bPDBjkHAi9EaY1DSKH61Jzgt2DqECDGcoK2prV/sWgTR0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=eSHxJm9j; arc=none smtp.client-ip=95.215.58.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Sun, 10 Mar 2024 15:41:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1710099723; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Cb7OKsY7pJ9Te/hhWi0i7nqCpNr5gLsM0TXwe5MbJsI=; b=eSHxJm9jvh4YY1rKRsZy9UXhw6N1OT5YboN9Hve5jsHATi2ski21RcYtJLhGKxV/d+DDes JxO6iUeNVTbRjc5EVGrKBiXFk0958xRzMaXQE1W+fXR0cylYK8n3XdywUICzV9DssAQtkP OH2zjTwYHtVAhmaL1oEb07OVZAvySLo= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Erick Archer Cc: Brian Foster , "Gustavo A. R. Silva" , Kees Cook , linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2] bcachefs: Prefer struct_size over open coded arithmetic Message-ID: References: <20240310110226.6366-1-erick.archer@gmx.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240310110226.6366-1-erick.archer@gmx.com> X-Migadu-Flow: FLOW_OUT On Sun, Mar 10, 2024 at 12:02:26PM +0100, Erick Archer wrote: > This is an effort to get rid of all multiplications from allocation > functions in order to prevent integer overflows [1][2]. > > As the "op" variable is a pointer to "struct promote_op" and this > structure ends in a flexible array: > > struct promote_op { > [...] > struct bio_vec bi_inline_vecs[]; > }; > > and the "t" variable is a pointer to "struct journal_seq_blacklist_table" > and this structure also ends in a flexible array: > > struct journal_seq_blacklist_table { > [...] > struct journal_seq_blacklist_table_entry { > u64 start; > u64 end; > bool dirty; > } entries[]; > }; > > the preferred way in the kernel is to use the struct_size() helper to > do the arithmetic instead of the argument "size + size * count" in the > kzalloc() functions. > > This way, the code is more readable and safer. > > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [1] > Link: https://github.com/KSPP/linux/issues/160 [2] > Signed-off-by: Erick Archer applied