Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp833312ybt; Wed, 17 Jun 2020 15:24:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwA/Qh2nJcTd4ZJMLg0PPzl8T5uJaovCn0HBDcepPtMKX4ll5ewAYg9zjZxdXVwrCcmx0iX X-Received: by 2002:a17:906:1e95:: with SMTP id e21mr1315524ejj.240.1592432678871; Wed, 17 Jun 2020 15:24:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592432678; cv=none; d=google.com; s=arc-20160816; b=vE4dqmiuYrO3ryaGAQV+5mOrsUjQQNX175+dxylwPo9JKBGvxtTcaTSMjOKBHdtA9o j1XuaRpdhVE8ktxt9KaUdflLluaLRllZSCbHnwxS5CE0eNS4euuVbYq6Mw+K+BAT1ToU qvP3TqBKIGpJesJTKx4knc3m/Yog/FW9XndJwmJMyvPLTt9VTGVwFNiV5EXLB6LS757X QXuD0qXF2eWNZbsKhb0DDbNOkDfIm9FhW5I7GrUL8s6mKgo/co0+3In+cPchC1q0ayOh FEw/2Pa1sgukgggb3oKYZ+HdVHi+vbr7AQ8MXaVhMLwDGaAWnM4QjFmHVRsrLZALHHri c20w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=im+hGDiWoAkNvBdT0uM7sen1yCXu5w8QBB2WRgpMdR4=; b=deUD9tTvIx/HE1gbYZee5LI+vlaW1amkQA5byJCNDOb65y1+EKGEpfql469mzQJBa9 cZM1jdJP4s0zrxzZfJNYqgbsyLItBbLyHM+Flz3QfLYqFLMDTjokhIaqAfLZb9CBFCDj 6D3+DwTfG0ll6UFeVG2ntMYMbyr2bVoEwZz4xDAzVxz8Q8me1y/H5ol4p10TBchIrBQB THyHdkGmpNEulDCpsiMUp6LxnSMWRpfyi3yKglkPGokXY9nXSPVmVfpbzsiyBN2YaxNY I0LdCn69mZQG/Q4BMb2FrnK9cbKWepRhSGqrg3hAlsL5/fziJIEy7ubQ11AqerNI+Ba6 lKxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="uQ/seVr9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id n18si767790edq.195.2020.06.17.15.24.15; Wed, 17 Jun 2020 15:24:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="uQ/seVr9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726954AbgFQWWN (ORCPT + 99 others); Wed, 17 Jun 2020 18:22:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:58544 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726909AbgFQWWN (ORCPT ); Wed, 17 Jun 2020 18:22:13 -0400 Received: from embeddedor (unknown [189.207.59.248]) (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 D6DF02083B; Wed, 17 Jun 2020 22:22:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592432533; bh=IXfRB1ln79N+EByGvcDZLtyLTc8uIB4owydFsSPvdn4=; h=Date:From:To:Cc:Subject:From; b=uQ/seVr9NqlnoEZpYrrDnKyihLCV1NpDqkPfISGAoZYQOTULsJr86NzD2lqElXJ7T 2Zum6blhRm7Y1SwcwF+vGdvbCjkqpQpOnrtSCdSNI5lgm/cCnzT8DhJXg8sI4G9oaN UgcFLJ7dfXMXROnRC88wxorAfsDSYFZELCBNot38= Date: Wed, 17 Jun 2020 17:27:33 -0500 From: "Gustavo A. R. Silva" To: Coly Li , Kent Overstreet Cc: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH][next] bcache: Use struct_size() in kzalloc() Message-ID: <20200617222733.GA24156@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes. This code was detected with the help of Coccinelle and, audited and fixed manually. Signed-off-by: Gustavo A. R. Silva --- drivers/md/bcache/writeback.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c index 1cf1e5016cb9..c0db3c860179 100644 --- a/drivers/md/bcache/writeback.c +++ b/drivers/md/bcache/writeback.c @@ -459,10 +459,8 @@ static void read_dirty(struct cached_dev *dc) for (i = 0; i < nk; i++) { w = keys[i]; - io = kzalloc(sizeof(struct dirty_io) + - sizeof(struct bio_vec) * - DIV_ROUND_UP(KEY_SIZE(&w->key), - PAGE_SECTORS), + io = kzalloc(struct_size(io, bio.bi_inline_vecs, + DIV_ROUND_UP(KEY_SIZE(&w->key), PAGE_SECTORS)), GFP_KERNEL); if (!io) goto err; -- 2.27.0