Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp606583pxb; Tue, 15 Feb 2022 23:34:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJxmTgpn6VP5keOYeJRQM19XUvfi08U0WJpnFCj7RvDmHu0YU6dFABiAOe1ipvIUzp+7N35p X-Received: by 2002:a17:90a:3d0f:b0:1bb:80e9:3b45 with SMTP id h15-20020a17090a3d0f00b001bb80e93b45mr304988pjc.31.1644996889276; Tue, 15 Feb 2022 23:34:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644996889; cv=none; d=google.com; s=arc-20160816; b=Lf+RUI3LoBUPnGh2B9o43kLDLrJFf2Ny/YljBp1O7RgQ7ZZvGxGP7v5/jOUtCZpR1n O2TeSJUBLa9TfwhGEpaen5zgkYWSVWHNIl1vkcPOl0PsFwa6YITa8dHEig2vDrLxW6Ob G1yYhVHUzUmlrIdAdyCheji1+IqKOmaU/BxPs7xh0smmnYN9RDQ7w9Kbbl06VoRa2ttX MnKidMhDqNtoDWk4HQn970Vll50MnK0kPFTIxSDLq4l4obNwubxgem/HbTk3BUO4+oBL CJUmcE2jIMNtWMHChW80OGA0S2+Kf1BbObildA85zXfynxmrxjpF0NtCTNqoRnAxqXdB lxqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=vIE0Izbh9CwLFYpchTer+Bxxv7Md5jVRn5sGjgstL6s=; b=NAyIAVxp5ZS6Ew83KBQmZxomm0dhLxQq+isTtvhHpZhl6anOfv8yloxdzcEASwiMDh AtZwC2eHy/0ZMBnKKFdx8aHcMOSSRVDmR2udEN4bRIoBYLV1M+ZHFRqhAE8b+/FrR7Xt MY0yn1sCFiaFTA0+tKakCXEwlj5sccKvMRuPCRTDAnetwJ0E2wgftdqx/RRc295ReP4M xd39Bmco9zXGqsMthT4RdwUsR5tOuDwq/NjAqgAcEyizq2y4l/a8EKqPpCi7jcCuC/9f qB8+9y4nSUGYcjtyCAujrBP4YiLdKCcFr37lq2OODIWWChm08pcIY70X8KelOOPgp6aY BMBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=MZMRcETk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c8si5639806pgq.661.2022.02.15.23.34.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 23:34:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=MZMRcETk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1B92F2AAB01; Tue, 15 Feb 2022 23:01:00 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344043AbiBPDIT (ORCPT + 99 others); Tue, 15 Feb 2022 22:08:19 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:34060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240415AbiBPDIS (ORCPT ); Tue, 15 Feb 2022 22:08:18 -0500 Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C15C59A994; Tue, 15 Feb 2022 19:08:06 -0800 (PST) Received: by mail-qk1-x72a.google.com with SMTP id g24so654026qkl.3; Tue, 15 Feb 2022 19:08:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vIE0Izbh9CwLFYpchTer+Bxxv7Md5jVRn5sGjgstL6s=; b=MZMRcETkkIkyTNGCOxnG5mHkgMIpGdQxIMbLccGCcWtZDo+OHc1NUu4+nsmfjtqpcC zqdBbkhar5/XBh/+qb4ChDQ2aXIOJ696r6+DUa6ZgVBhDq2IQJmaQNM31vuv2+vWHoKU gDLrgNYT5AivhBKptqoq8LfawnOi1+feZ69N5Nq49WBZQfqzyFeFfXBtEqG9Zv2Up7/i iZN6tvBq9qpFf3VY8zJyzFPDwysYu3NgwqP5hu5T0ygv81gX/g6l2cCFCgXv4fE3MLY7 4Dx5tsXfiy7szMZMNRAVQ59T3Xh3EyK5Kh4G9amEE8sJG4gvaKgnmXbYbWppJ1nRE7bB FS+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vIE0Izbh9CwLFYpchTer+Bxxv7Md5jVRn5sGjgstL6s=; b=obPD2mREG/TSK5G0nLfRwjAatFh1VWjerDOEptCJ2zLm/hobkvgRCZGWYOOmxc7B3F 87wmZGXgCdL0cJtvTqQ96ysHohOQbZXL8zP9h//K0dmayE3h4BIMihqN8ECKGAucPTFA f3HUhaSXMZrEY/+aUgGgLrAQ3EgOXE8n7xR8AS2wdrV4VrWGZ2YD/SDw6DOjstF3pLai BN45m2hGmLrCgAMDFW2SAM7w7jqcdSs/2xAvIZzbf4PlV3VphTP7k2PhPxqymLam3lUg 3tgHOnTzcCuJqXhsL509Za/Wz/T0jbqR4OlaivtapV71P02OVJN7IMp5QfKCBUdCPppM dnzQ== X-Gm-Message-State: AOAM5320lGuqcR1Tj8hOYzyFtARdLa2fr7tnwctuGV0Yd+tjw84dozB9 0RmlYENJ/faG1SOFVYHgmV0= X-Received: by 2002:a05:620a:152a:b0:46d:5918:e7cd with SMTP id n10-20020a05620a152a00b0046d5918e7cdmr418881qkk.494.1644980886019; Tue, 15 Feb 2022 19:08:06 -0800 (PST) Received: from localhost.localdomain ([193.203.214.57]) by smtp.gmail.com with ESMTPSA id w19sm15781791qkp.6.2022.02.15.19.08.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 19:08:05 -0800 (PST) From: cgel.zte@gmail.com X-Google-Original-From: chi.minghao@zte.com.cn To: agross@kernel.org Cc: bjorn.andersson@linaro.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, "Minghao Chi (CGEL ZTE)" , Zeal Robot Subject: [PATCH] soc/qcom: use struct_size over open coded arithmetic Date: Wed, 16 Feb 2022 03:07:59 +0000 Message-Id: <20220216030759.1839582-1-chi.minghao@zte.com.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Minghao Chi (CGEL ZTE)" Replace zero-length array with flexible-array member and make use of the struct_size() helper in kzalloc(). For example: struct apr_rx_buf { struct list_head node; int len; uint8_t buf[]; }; Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes. Reported-by: Zeal Robot Signed-off-by: Minghao Chi (CGEL ZTE) --- drivers/soc/qcom/apr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c index 82ca12c9328a..0813dbc5e462 100644 --- a/drivers/soc/qcom/apr.c +++ b/drivers/soc/qcom/apr.c @@ -171,7 +171,7 @@ static int apr_callback(struct rpmsg_device *rpdev, void *buf, return -EINVAL; } - abuf = kzalloc(sizeof(*abuf) + len, GFP_ATOMIC); + abuf = kzalloc((struct_size(abuf, buf, len), GFP_ATOMIC); if (!abuf) return -ENOMEM; -- 2.25.1