From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (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 A397F347530 for ; Fri, 27 Mar 2026 16:17:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774628224; cv=none; b=ZP9JjY8+zlJpH0L1+7JjL9wzvlhJdFD3okCA6fHf4fAQWNt4vKrWTO5pfjxlt+GapbkxfUMptsCucoJIKLlEpL+IKFaSxjD403sQpnI0UJKRqpD3RhQkesQz8GlePoz3EjnHThRJ0rBC3MDxPS0f8xUah5i62iCaG4Q31yehbfc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774628224; c=relaxed/simple; bh=SVdTkeVeyoLe/1KQceMwBisVnJtenJGNsKgIsNp7LRg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=eCsc8HxXNdUXvmGfg2NtvdwkDGvRSTYbDw2t8l0QogPEWspf8toKWDcWA0IzDKL6XhI83npNgEyTlbMuag7PBV/V0a8rg0U6XDP+pH06QmcQL1ConsMu6RAaPnxxFo05VKxvdoKYMGNePsikGgQqCy8gv171Uux8x4INTWdgPcU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=EhaMoWgP; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=icrrug/Q; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="EhaMoWgP"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="icrrug/Q" Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 62RG3Iah1955274 for ; Fri, 27 Mar 2026 16:17:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= h0uSEuoFInxVgrwB79dUUBt3ZPYXBustTfB6r5GqV4g=; b=EhaMoWgPsnhiqVsV Nd8oSZSoky4XsXx2YeRGcDZypaTTiinDsVBfXcuUhTn+zWujbfYDyryYb59/V2d1 msvX6uzquKSoiKUM6grtzA/ptTlc9QLxhXJUBgbQFXAZl+Hgq5FXas41nEa6lB+d lD+j6uv00oS23F8x8E0uMeOCmZvewQfWQU2jXuJVmJvyulrZizOiXQw0zNZfS8Qe yEN1tmzAX85sBFUvmZRnNbmaEMHX8sLZ+4tGUnrrfBblFaxF2/Tm+f2Okt4JmeT5 0gZr9PcmbNctyCJw5myhyQTEG0GlDvQFS5M4UmsbLcQjUtUNcvREvA7QOfQbPSvU N/dLig== Received: from mail-dl1-f71.google.com (mail-dl1-f71.google.com [74.125.82.71]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4d5w30r23t-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 27 Mar 2026 16:17:02 +0000 (GMT) Received: by mail-dl1-f71.google.com with SMTP id a92af1059eb24-126e8ee6227so2363950c88.0 for ; Fri, 27 Mar 2026 09:17:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1774628222; x=1775233022; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=h0uSEuoFInxVgrwB79dUUBt3ZPYXBustTfB6r5GqV4g=; b=icrrug/QV6WcjG8MOlphALEFcmOttNPIEp3xIkq7zz5chVeLRPKMrKoRIh7g6KxUQD PX9NayPAF0oiGYwQqE4YOWOydlVkEZqgGg6AGd0rDp+qR2x1ur6je+BjcmxXvTAwoue6 ue8DEzMJfXaMYj439viYFENUMdk+/QxlpBcSJjJAVPjhFgY7F0rQkgC1jtdBiuDzBXMI W+KfHskW/7pmJy3oZo5LY/fgm41WAgZtud9KAVJ0totI+b77JR5ry7aCjUOo0qlBpcSP CQ+MCPB2DDHxQdIlxvLN6nmmYo3eEKbNGV2TNbRyFYVYv1WcEQ8SUl9T8AYNhgtj2v4F hHEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774628222; x=1775233022; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=h0uSEuoFInxVgrwB79dUUBt3ZPYXBustTfB6r5GqV4g=; b=Bn53PHsa780zwm1QdssFr1lt6uFcQBNZZ7d80A3o6qEd0mh4qPEmnXwjDg+D0Z/U/X lSLL5/jnZKiuCA6weJFa9BQMEevOEOuvR15i8dXDHwGKnODQWTJsSbRVCL0umrlESXw9 cUKj6oYnIM3Y9/M0atmqI5Ze0NTo5g8n6I4r29HDi3XPVSLqz88GWlGM+Av33oErPVab C/VsgEwbLHizbGrOpQyr4PGBMjJInJHhn33cP+/tsrtgSmQc9C6t0MBlD99ZEvYF0kjV s5VGDA2XSOZvW/HYE3NleQssnL/LFWDOA7eA0CiDLcWDq2e9D/+YBz0tFR5GCSjYc7P8 IOSQ== X-Forwarded-Encrypted: i=1; AJvYcCWvq5B0pHRoi4GjK82JjvXsyxM0+WSKs+TH8q4AVWa1vydX0dmSU8bDssKbYfn3MwhA19sLm+Zj23OigLk=@vger.kernel.org X-Gm-Message-State: AOJu0YwBSU5l83/CxByfVhb/iXFbaQfzXSngHE5QO5BeAXNiFopjkd7M 4baqpuoSKBbm+2sb/D4T+CHNBHOIYfVefilnMzoPqW4mCqQPFpNCnZwpFisTzsE0revZ6XnmEAH jBFrVkubgQUJKuRADbQlzAH5Jly4uclrd22gV9vBdveR/MTLIL24jt/7iuBkBmCiMms8= X-Gm-Gg: ATEYQzyvYWqZSZhRy4EqpGjfgJXKNuDzQHCrp3dJe4IK1AKp60DSu962LKMCW52U1GZ i1jMKJCznJlrHO73eDQTRvzozB6G8naoesvmO3LEofovO+xQqwF7qdkS3KDRZCLV+zF8+ozol6t cpw3aNdjbg9VOcLBCuQOC0F3wOw+SfzihY75fD2lrjxAOFc8yM/ut1ssvLr4T7DICw1+PZoRNc6 5L2Rr8hKueRJ1MWFSMVFCDAGgn6preBNIPuSHl+sfofMYABGjfh4Gj7iPCp1OrwKFNd/XMWnnOB jeYi2vpyU4vqBcsot6GxWwSU251MaheuWEsDcmONqKVeum3LKgZD2JdHenz928IVXUWk5A994b2 ZWI5SHhe6KPZ6xT+QXj+IdGG4kEYENc15Ptx3R6AUaSSpYa0XU0B2RETOPunXzot92hLCMYSJRt g= X-Received: by 2002:a05:7022:618a:b0:12a:6b99:1ad4 with SMTP id a92af1059eb24-12ab286cf5amr1634007c88.11.1774628222061; Fri, 27 Mar 2026 09:17:02 -0700 (PDT) X-Received: by 2002:a05:7022:618a:b0:12a:6b99:1ad4 with SMTP id a92af1059eb24-12ab286cf5amr1633983c88.11.1774628221305; Fri, 27 Mar 2026 09:17:01 -0700 (PDT) Received: from [10.226.59.182] (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-12aa7624247sm8135794c88.11.2026.03.27.09.17.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 27 Mar 2026 09:17:00 -0700 (PDT) Message-ID: <5abe5ee7-f054-4e32-ad9a-c9b8f10bc423@oss.qualcomm.com> Date: Fri, 27 Mar 2026 10:16:59 -0600 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] accel/qaic: kcalloc + kzalloc to kzalloc To: Rosen Penev , linux-kernel@vger.kernel.org Cc: Carl Vanderlip , Oded Gabbay , Kees Cook , "Gustavo A. R. Silva" , "open list:QUALCOMM CLOUD AI (QAIC) DRIVER" , "open list:QUALCOMM CLOUD AI (QAIC) DRIVER" , open "list:KERNEL" HARDENING "(not" covered by other "areas):Keyword:b__counted_by(_le|_be)?b" References: <20260317003034.71618-1-rosenp@gmail.com> Content-Language: en-US From: Jeff Hugo In-Reply-To: <20260317003034.71618-1-rosenp@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Proofpoint-ORIG-GUID: 0h8wuuQRMOZsQdnNisADN6omlrpm2RIJ X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzI3MDEwNiBTYWx0ZWRfX6r6RSkyzZ6XG NCV3ob1smNWngcblnVXCRIiFSY95KJrdLrbgp+yG0NdS5MBkO0vas3FANkS8SzubXOGL4XnRNs8 lZFTjDgAJpDVHsH8Y10e4Vu06ZmF385WeJ6E1sWcARdVLK/uCmFG7neatB7PLSC6Q/l8dKgRbsr kWV4KiXAPLnoW4VIYw9z3N3ZFk4nPhD7jSNtueyDZSvVBv/34GqPrKfCRzkhGGyEBnee8WjxSQk WXOh8hAvO3Z9a4no0ToNHGJsQCSs5N7+cQRfGXyGAg6CB9ur9xQhYFP0AfJqYBPRHUeP4d2Y0P/ vCBX6YnGnp4+Bh/+I4i5F36ZHeamBYvLHj4VVjytisDDxrpfN5TPN9Z3a/Dmek/JWXQyoqHQQsv QyPe//ekxBuKtNJcza7eCg0J04fBJ7ug1EOD1N7ci55Wx/M9FZ5MbU13Wk16PvQ0OOEkp+B7fCf SGJGDM+XBiIUFzS0g3w== X-Proofpoint-GUID: 0h8wuuQRMOZsQdnNisADN6omlrpm2RIJ X-Authority-Analysis: v=2.4 cv=F9dat6hN c=1 sm=1 tr=0 ts=69c6ad7e cx=c_pps a=JYo30EpNSr/tUYqK9jHPoA==:117 a=JYp8KDb2vCoCEuGobkYCKw==:17 a=IkcTkHD0fZMA:10 a=Yq5XynenixoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=YMgV9FUhrdKAYTUUvYB2:22 a=pGLkceISAAAA:8 a=H-3xqeJHN62Qb4ZhkN4A:9 a=QEXdDO2ut3YA:10 a=Fk4IpSoW4aLDllm1B1p-:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-03-27_01,2026-03-26_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 clxscore=1011 priorityscore=1501 impostorscore=0 malwarescore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2603270106 On 3/16/2026 6:30 PM, Rosen Penev wrote: > Combine allocations by using a flexible array member. > > Use __counted_by for extra runtime analysis. Move counting variable > assignment as required by __counted_by. This fails to answer "why". This change is not justified in the commit text here. Please see "Describe your changes" in submitting-patches. Also would be helpful for you to mention how this was tested (although those details don't need to be in the commit text itself). You are touching arguably the core structure of the driver and any mistakes will be devastating. > Signed-off-by: Rosen Penev > --- > drivers/accel/qaic/qaic.h | 4 ++-- > drivers/accel/qaic/qaic_drv.c | 7 ++----- > 2 files changed, 4 insertions(+), 7 deletions(-) > > diff --git a/drivers/accel/qaic/qaic.h b/drivers/accel/qaic/qaic.h > index fa7a8155658c..e237020f6aa9 100644 > --- a/drivers/accel/qaic/qaic.h > +++ b/drivers/accel/qaic/qaic.h > @@ -152,8 +152,6 @@ struct qaic_device { > struct list_head cntl_xfer_list; > /* Synchronizes MHI control device transactions and its xfer list */ > struct mutex cntl_mutex; > - /* Array of DBC struct of this device */ > - struct dma_bridge_chan *dbc; > /* Work queue for tasks related to MHI control device */ > struct workqueue_struct *cntl_wq; > /* Synchronizes all the users of device during cleanup */ > @@ -206,6 +204,8 @@ struct qaic_device { > void *ssr_mhi_buf; > /* DBC which is under SSR. Sentinel U32_MAX would mean that no SSR in progress */ > u32 ssr_dbc; > + /* Array of DBC struct of this device */ > + struct dma_bridge_chan dbc[] __counted_by(num_dbc); > }; > > struct qaic_drm_device { > diff --git a/drivers/accel/qaic/qaic_drv.c b/drivers/accel/qaic/qaic_drv.c > index 63fb8c7b4abc..ab428ecd26f5 100644 > --- a/drivers/accel/qaic/qaic_drv.c > +++ b/drivers/accel/qaic/qaic_drv.c > @@ -405,15 +405,12 @@ static struct qaic_device *create_qdev(struct pci_dev *pdev, > struct drm_device *drm; > int i, ret; > > - qdev = devm_kzalloc(dev, sizeof(*qdev), GFP_KERNEL); > + qdev = devm_kzalloc(dev, struct_size(qdev, dbc, 16), GFP_KERNEL); I dislike the structure of this change. 16 is now in multiple places, and when it will change in the near future, its going to be harder to get the update right. The existing code specifically assigns the value and uses the value from that assignment for that reason. > if (!qdev) > return NULL; > > - qdev->dev_state = QAIC_OFFLINE; > qdev->num_dbc = 16; > - qdev->dbc = devm_kcalloc(dev, qdev->num_dbc, sizeof(*qdev->dbc), GFP_KERNEL); > - if (!qdev->dbc) > - return NULL; > + qdev->dev_state = QAIC_OFFLINE; > > qddev = devm_drm_dev_alloc(&pdev->dev, &qaic_accel_driver, struct qaic_drm_device, drm); > if (IS_ERR(qddev))