From patchwork Thu Aug 3 22:20:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 709596 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:606:b0:129:c516:61db with SMTP id eh6csp157188rwb; Thu, 3 Aug 2023 15:21:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEW0QE+SsVbT7BqvgIV+1LJydatcI1Mhgc7jDrc23sp7lrEnys2YOtSMGmaG2FZEi6p9Cmp X-Received: by 2002:a05:6214:76e:b0:623:8494:9945 with SMTP id f14-20020a056214076e00b0062384949945mr12220qvz.26.1691101314852; Thu, 03 Aug 2023 15:21:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691101314; cv=none; d=google.com; s=arc-20160816; b=GrEAyx6pE94QOCMdL+/u/YN6CqmNu4rYIoP+ArDk1A+gTnhPq5zZqPgBZTR9pcmfGd uZ6hcXuGKEYh5AaNfIp7YZScKQfkMIZ4mBpMI2SwEmG9hZxVqEUCulGvyVy2cKixIXEW RW7Rxx2FY0gkT19ATMmt00585pLKVbsm8rRZEN/NEol8eNs+BHd9ecSK1FWL0/5RHbdv R4Q7k0hSLYwK//iPHPulhpNTwJQHZfjaHuXNA27T+FigDaIGSXF8VFSPFsBToetULD9y wccFrmGo7GW9v1CTHu1RRl4cZMQNWhflVQfk2YJnT3k2/osqYEoWNbXY9OThV8FiN8CD gKNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=4GzWS5FnIrPDtn2Htg+CctKW805+xbLzE7TTNfE7rtM=; fh=UrBDiNPBBZta6vhTNqUbYrjrYJEj4BZWQsPczQ0Fhnk=; b=bbW8Gd2Yarsu8q7JkURb+Xe0h3p2CVdZfn1EUP6vyKeCNXemnBFcnnR5grZu2Rf0+P u6Bekp5yx3s3GTjXhT5nxaVMySq/nSqP5r6Macwa06A198/M94T9lxyGxyESL4lxI5tL fkr3CClWQVHDMbOqQ27FHl42jHgFMvlNoiSICJxz+lkxOIQJU3UvAVuKzoUKbeoaKaoy 7UOt01vhlA9MmIsYhsqxg1b9NMipGQjV6CAEqW9BPNqY8xQRs2JikyziUhPEzpQBNSvc +rUA3wQjq+W1X4dr9O3nTOMZmM+qcXvv96R3KCLeikIfvL/X9Y5WzXEwTy+sECc62lji KKeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=etWVgu4F; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t8-20020a0ce2c8000000b0062fedfa5dfdsi404998qvl.93.2023.08.03.15.21.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2023 15:21:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=etWVgu4F; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRggm-0004Hd-GZ; Thu, 03 Aug 2023 18:21:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qRggk-0004GH-IJ for qemu-devel@nongnu.org; Thu, 03 Aug 2023 18:20:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qRggj-0000Ox-27 for qemu-devel@nongnu.org; Thu, 03 Aug 2023 18:20:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691101256; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4GzWS5FnIrPDtn2Htg+CctKW805+xbLzE7TTNfE7rtM=; b=etWVgu4FvwNQohfgR/SjIToCMx74In6g7spmo14TGye5XOolOz81cRBUBrYH8gyybvDMmM /JoXAJ6ldM8kdFwmY5utgFFl5Z1PahNgPItP6osiO7uQUInwkpoRHjpWI2xVtbd3s5+Hu1 S9m1/99laHQhucN44uHwLOzIOoWEAdU= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-648-hHztSPF9MAqT-PLREt3HQA-1; Thu, 03 Aug 2023 18:20:53 -0400 X-MC-Unique: hHztSPF9MAqT-PLREt3HQA-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-99c01c680beso86834766b.2 for ; Thu, 03 Aug 2023 15:20:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691101252; x=1691706052; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4GzWS5FnIrPDtn2Htg+CctKW805+xbLzE7TTNfE7rtM=; b=Sb1pbeNeim8UxQbe6ccl7/DjQw4SfPImDOO2+bzBSkskBO2+MSrtk3TKZKX0no8Gvr dKTJUrxt96xI+WZ8MAT25NGS7Aul+Ad74YFM6bpd9DVqdNL2vYfYAObZVD0KK/NdkjlQ peSB22+TDMQAmgRqrDErhGE9ByWK6wpzRLwvWmRDjp+xefrdM1njc16dRMtNtR8KISvJ eCJY73JKQlvnRGZ3EU4ePf2UjXaWfFK294LXbo+kW514jEckQnGTkTq2mZcFQGs/ypYT ehswl2FtYi6AiiWUN6JZosFVAIZ8DXSmFGEf527i4ej8Q8/lfuiRb+yAAyzrHa43M8sU XyzA== X-Gm-Message-State: ABy/qLYXN01yGJD8v/EBczzBzLh5i5RXoE//LW0VT30XvBYoBQjkzeKd jA+IFMKv+jgC6y6sl4UIhFUVHJ7gSvmGXbftKQJqIAn3h6ctkZvlaBjTz01Omrp8Q/PrMcEOl3d +EBUqzeEIo19vf/Iv3OGiGbLgeocs/fuh7xrt0Ao7KiMhxlF0Cdc6s1iot6TPJ3o95MYF X-Received: by 2002:a17:906:ef8f:b0:99b:6c47:1145 with SMTP id ze15-20020a170906ef8f00b0099b6c471145mr8307713ejb.32.1691101252023; Thu, 03 Aug 2023 15:20:52 -0700 (PDT) X-Received: by 2002:a17:906:ef8f:b0:99b:6c47:1145 with SMTP id ze15-20020a170906ef8f00b0099b6c471145mr8307703ejb.32.1691101251772; Thu, 03 Aug 2023 15:20:51 -0700 (PDT) Received: from redhat.com ([2.52.12.104]) by smtp.gmail.com with ESMTPSA id a1-20020a1709063a4100b0099275c59bc9sm379916ejf.33.2023.08.03.15.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 15:20:51 -0700 (PDT) Date: Thu, 3 Aug 2023 18:20:48 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Philippe =?utf-8?q?Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , Jonathan Cameron , Marcel Apfelbaum Subject: [PULL 02/22] hw/pci-bridge/cxl_upstream.c: Use g_new0() in build_cdat_table() Message-ID: <503d86dd66625b4bed9484bca71db1678c730dc9.1691101215.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Peter Maydell In build_cdat_table() we do: *cdat_table = g_malloc0(sizeof(*cdat_table) * CXL_USP_CDAT_NUM_ENTRIES); This is wrong because: - cdat_table has type CDATSubHeader *** - so *cdat_table has type CDATSubHeader ** - so the array we're allocating here should be items of type CDATSubHeader * - but we pass sizeof(*cdat_table), which is sizeof(CDATSubHeader **), implying that we're allocating an array of CDATSubHeader ** It happens that sizeof(CDATSubHeader **) == sizeof(CDATSubHeader *) so nothing blows up, but this should be sizeof(**cdat_table). Avoid this excessively hard-to-understand code by using g_new0() instead, which will do the type checking for us. While we're here, we can drop the useless check against failure, as g_malloc0() and g_new0() never fail. This fixes Coverity issue CID 1508120. Signed-off-by: Peter Maydell Message-Id: <20230718101327.1111374-1-peter.maydell@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Jonathan Cameron --- hw/pci-bridge/cxl_upstream.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/hw/pci-bridge/cxl_upstream.c b/hw/pci-bridge/cxl_upstream.c index ef47e5d625..9159f48a8c 100644 --- a/hw/pci-bridge/cxl_upstream.c +++ b/hw/pci-bridge/cxl_upstream.c @@ -274,10 +274,7 @@ static int build_cdat_table(CDATSubHeader ***cdat_table, void *priv) }; } - *cdat_table = g_malloc0(sizeof(*cdat_table) * CXL_USP_CDAT_NUM_ENTRIES); - if (!*cdat_table) { - return -ENOMEM; - } + *cdat_table = g_new0(CDATSubHeader *, CXL_USP_CDAT_NUM_ENTRIES); /* Header always at start of structure */ (*cdat_table)[CXL_USP_CDAT_SSLBIS_LAT] = g_steal_pointer(&sslbis_latency);