From patchwork Thu Apr 18 07:59:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 13634309 X-Patchwork-Delegate: kw@linux.com Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A837278B49 for ; Thu, 18 Apr 2024 08:00:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713427211; cv=none; b=fiBUYzDEpdzCxqShr+0eGPBaT6H6tZfxh1xQFHb3h4pxgv5fcHkmXvZUEHcFflX91+fayHv3LMY68BCe+lV92tNaDZ6lskxrycrz43l3JC+V6Ru7qaqkxJg3tj4D6vE0QcatT71qBai+U6jRJEpiImqOoqmO76lsQFN4HYEWbYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713427211; c=relaxed/simple; bh=+dPJhpBZ6Z9Bvg50ANU6nm5U04Z4RKW/SsbP2j5yqfg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oWI3COeZslGyH2s51RNsFaDY4Z94Qag4L1OI3D5VpgXW6M3MBnYMq7FSqmkRxxHASDC8snnV6LnDZoicL7u465lhvH9b0ASNu067Yr8Zq98/Jn4Z4W+yOZY0PWW5LWeickOLQUDWHVSxsyWZttdNBqdxj9BfpOmgBI7xT0vZk6Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Z1b38tM1; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Z1b38tM1" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1e651a9f3ffso3778875ad.1 for ; Thu, 18 Apr 2024 01:00:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713427209; x=1714032009; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=1bUXYeNx7u3tu+bha+S/5ez5PzMF1gaI6KQP6MUtJvI=; b=Z1b38tM1gWHD8nFneGgKnZOGy2AhzH4bzPLB2ct6BQwikNU6/AMhTzMifHrIeQXvgS MhinchFCuL8MTVZebwL1o5Xyu29u5PERZoHdhH0yr0GYQvtzbqTC0P9C+IZF4jqf84J1 4t1NdtEx52Xzk39cNVd14mgVPOVf5MNPDvSFpFPVY5jXSYr/BeRuekAYl8tUuKp8V2fF q/rntlwaP+FT5yUfcq6qND5PvwVJvRTZpocqgd4RV1EwF9gV7XL9tdy8uV/91AVi24i8 lxoWWzn3U8nEx1ms+J1O81GKBq2pyEPzSjAM9pPtO3X39jNIKA0WpjXA6d6ekoATnZO/ n2xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713427209; x=1714032009; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1bUXYeNx7u3tu+bha+S/5ez5PzMF1gaI6KQP6MUtJvI=; b=Asuf5vZqS6SZJvIVcvn6ap/8g8hrdY8SKRVSCNGOOhmVDZEb1kQKj93kKi1LFfXVpg I6CV9KuLyuoHmq/1+smev4EYuSWFC/zl+wd8+fGBDFOtX8gUtHn8i+BTq0y1WYAPZh9M NZsJPZ3psouJ9c5TNqGMARIGU/uxLyP0GzieiCNTjhWWoqYc35lfcaTV5DynnJOmK4e7 JTSnl9dKNvqvd3wP4hkD/ql3AT9W0oEmOsgALl727vHQB2GBw+lSYah26q6wyLw4BGnX HzdyTdyNYy0Biv6xPjSb1cJwxn9ruxtrXoKJdbUNMGLd91EHd5hSd65MRCTZoFpYWQcJ DLiw== X-Gm-Message-State: AOJu0Yy/SuPDq01MqEiweIou8Ad1RgUFdny7TLKbEHFB9hcHcqiDG4GE z/m9hOorOhEvCk/qe2VMlW5/KDcaNiJAbA/5v/s15Gc8Qhf531eSDUBIdG0PzA== X-Google-Smtp-Source: AGHT+IHyoPFQlFoXtgY40googjyG4b/IPCLMz9M13nObHKBj6NsKcJCqoQzLHYGR4bg6XNUk30j9PQ== X-Received: by 2002:a17:903:244f:b0:1e4:47bf:6926 with SMTP id l15-20020a170903244f00b001e447bf6926mr2516174pls.4.1713427208644; Thu, 18 Apr 2024 01:00:08 -0700 (PDT) Received: from [127.0.1.1] ([120.56.197.253]) by smtp.gmail.com with ESMTPSA id lo8-20020a170903434800b001e546a10c50sm889956plb.286.2024.04.18.01.00.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 01:00:08 -0700 (PDT) From: Manivannan Sadhasivam Date: Thu, 18 Apr 2024 13:29:58 +0530 Subject: [PATCH v2 1/2] PCI: endpoint: pci-epf-test: Make use of cached 'epc_features' in pci_epf_test_core_init() Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240418-pci-epf-test-fix-v2-1-eacd54831444@linaro.org> References: <20240418-pci-epf-test-fix-v2-0-eacd54831444@linaro.org> In-Reply-To: <20240418-pci-epf-test-fix-v2-0-eacd54831444@linaro.org> To: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Lorenzo Pieralisi Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Niklas Cassel , Manivannan Sadhasivam , Dan Carpenter X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=2897; i=manivannan.sadhasivam@linaro.org; h=from:subject:message-id; bh=+dPJhpBZ6Z9Bvg50ANU6nm5U04Z4RKW/SsbP2j5yqfg=; b=owEBbQGS/pANAwAKAVWfEeb+kc71AcsmYgBmINMAYZWQ9fwZiwl1pCOKA3kyB/eiUU1F0L9bZ runv8zRI+aJATMEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCZiDTAAAKCRBVnxHm/pHO 9WM4B/9ZeGWbuXnjR4+7h9CZgLQ0vMxh/i6wPAid348nY5SPMlgWPWRYM3j4yN6Os63DWBjK6nQ iNKBYwHCiuF2T0LdOZnKZzq2h6ISixgtK7cID1C30bMhm6JTSyBP1oFrkzWPKadRfL0rBx5rFgv U5rTNPzvmhQEIY/rVAaM+abkAeAXwM1jSNm0XQBwrZb9IgKcBZuyxplL/5utU9kiAG75TatSgU8 GcW2j/mKMFJor/Yyqk49tUq+AHviHvkcioV2mb2+EbQ+blWCIS7AOabeHCtywXc8AyNrN6V4aLv VVbhiIGD4EA06ADsxjwWuqkM8DoJnUdCfhncLWhNTw0wHo9y X-Developer-Key: i=manivannan.sadhasivam@linaro.org; a=openpgp; fpr=C668AEC3C3188E4C611465E7488550E901166008 Instead of getting the epc_features from pci_epc_get_features() API, use the cached pci_epf_test::epc_features value to avoid the NULL check. Since the NULL check is already performed in pci_epf_test_bind(), having one more check in pci_epf_test_core_init() is redundant and it is not possible to hit the NULL pointer dereference. Also with commit a01e7214bef9 ("PCI: endpoint: Remove "core_init_notifier" flag"), 'epc_features' got dereferenced without the NULL check, leading to the following false positive smatch warning: drivers/pci/endpoint/functions/pci-epf-test.c:784 pci_epf_test_core_init() error: we previously assumed 'epc_features' could be null (see line 747) So let's remove the redundant NULL check and also use the epc_features:: {msix_capable/msi_capable} flags directly to avoid local variables. Reported-by: Dan Carpenter Closes: https://lore.kernel.org/linux-pci/024b5826-7180-4076-ae08-57d2584cca3f@moroto.mountain/ Fixes: 5e50ee27d4a5 ("PCI: pci-epf-test: Add support to defer core initialization") Signed-off-by: Manivannan Sadhasivam Reviewed-by: Niklas Cassel Reviewed-by: Frank Li --- drivers/pci/endpoint/functions/pci-epf-test.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 977fb79c1567..546d2a27955c 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -735,20 +735,12 @@ static int pci_epf_test_core_init(struct pci_epf *epf) { struct pci_epf_test *epf_test = epf_get_drvdata(epf); struct pci_epf_header *header = epf->header; - const struct pci_epc_features *epc_features; + const struct pci_epc_features *epc_features = epf_test->epc_features; struct pci_epc *epc = epf->epc; struct device *dev = &epf->dev; bool linkup_notifier = false; - bool msix_capable = false; - bool msi_capable = true; int ret; - epc_features = pci_epc_get_features(epc, epf->func_no, epf->vfunc_no); - if (epc_features) { - msix_capable = epc_features->msix_capable; - msi_capable = epc_features->msi_capable; - } - if (epf->vfunc_no <= 1) { ret = pci_epc_write_header(epc, epf->func_no, epf->vfunc_no, header); if (ret) { @@ -761,7 +753,7 @@ static int pci_epf_test_core_init(struct pci_epf *epf) if (ret) return ret; - if (msi_capable) { + if (epc_features->msi_capable) { ret = pci_epc_set_msi(epc, epf->func_no, epf->vfunc_no, epf->msi_interrupts); if (ret) { @@ -770,7 +762,7 @@ static int pci_epf_test_core_init(struct pci_epf *epf) } } - if (msix_capable) { + if (epc_features->msix_capable) { ret = pci_epc_set_msix(epc, epf->func_no, epf->vfunc_no, epf->msix_interrupts, epf_test->test_reg_bar, From patchwork Thu Apr 18 07:59:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 13634310 X-Patchwork-Delegate: kw@linux.com Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E0127BB0C for ; Thu, 18 Apr 2024 08:00:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713427213; cv=none; b=jib9v/SOt0VG3kqz35hpfQo69FXD/n6Aj7dr+8Ec831hEt74285xAT1eukMsbzx8BEjAeSngchLyCi9nTmASspG+rdg7ztvIjiGzGDyXNdpHLptmhURM60Mhlg1A9/A+ZCHxWIJjGM5QpJbfxNVe9mtXPTuanHWJr4N7JKBXc38= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713427213; c=relaxed/simple; bh=dx7Pu4GSAq806/2nc7mcGWRQfuaNyNK4rj6uW2+wJD8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZETCaqycsS0IML3jobGYsBz8ipyzpi4XE7qLpqfX0gIkuoMvhBTDYYcAomwXec1CtPAEUJYjehdQjZ9evpcl+MKX1/imSwsgIfm7Pwc4o9fpNuZ0xBXM/SRmlswVTOW1391O9bVhHkCpaFcvYf7n0xAZIFKObr+HEeuwP1S5hSg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=rmwV2Ryd; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="rmwV2Ryd" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1e36b7e7dd2so5034555ad.1 for ; Thu, 18 Apr 2024 01:00:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713427212; x=1714032012; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=nmNqm7iwZFYKOgfpdWXEANgZEqRwFMnPvW+zA13+SJs=; b=rmwV2RydkUmuWYF2Knz90kOJE40CMz+PdHxBCEvX0NinaUm4sBB9a/HTuevBGXpTht Ajaevc+D3g+amXwNOB9oprm8sGCIhblB3L1mXPC5leYbMWcJdilCDUxGKm26uUMbIPeG 9rWbz1ecIMYnH9xcNQGxhzBD1HW6T4z5yydX3UGep72ADr2nCPtaGumP75YzJmfX0DCW CslAanFtMQAU7LMFOzDPIlnevrdctSlMctMXT5VjtcuI3pztrQOSAcYCfwYqZO9t2rPm Fz0q9lRR+LpuhPw9N5B9ecSvW57n9ZZc6m0e2CsUqP3crrLQB+EyEaI7JF8teYDZCsJU sYTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713427212; x=1714032012; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nmNqm7iwZFYKOgfpdWXEANgZEqRwFMnPvW+zA13+SJs=; b=o4ithKso6bifbsf+hdZVnZm5R3Ctlu4ULm3uBe0FMOqlMysE6pbYJxS8vEHGra0lBG YEmDkTdHYqJiZMX5BS3bK1XtT4bIX+TNemNrp/8I1VKnmEz4ebNcVCSND6yre46b5Y0i olr2FoB5TNhE4UXfsLj1zbUZWF6cN5vMwY/09PvINcHAVfsmV1JAU5oNMgTaHwLL29GZ 5uJ5ORKSoDPJEvdFP11id/uEH42aefUr8UYZXf0xIA3BcWkzgXPTWIqYFSlsi0iN6rav H1BfP3v8A2iFR3rjY6LwaMNyX9UpmUgjWKy8RPorcuzgZQY4n+vq0hXjW1Fq0VKeoygZ tYBA== X-Gm-Message-State: AOJu0Yz/1q16A0Np1vYUbdlMrnwhFl68Dqx+ufkSzILo45WMLp0kLe0P 4R0z7jdHnlxmoRmCSra8Qczle2X0Yj8Hxdery6SKE+Dq7PFF22tBY9wRmJqr/XNetjwpxZ+sFBg = X-Google-Smtp-Source: AGHT+IFsdTsbM7dhIhKZYJ6YbLdedOkZDV8WFJ5e3qauhUx4R1UbGZ4dAe8MDYRyW/9F2ULB2VwWJg== X-Received: by 2002:a17:902:c212:b0:1e4:4955:98d9 with SMTP id 18-20020a170902c21200b001e4495598d9mr2092824pll.45.1713427211626; Thu, 18 Apr 2024 01:00:11 -0700 (PDT) Received: from [127.0.1.1] ([120.56.197.253]) by smtp.gmail.com with ESMTPSA id lo8-20020a170903434800b001e546a10c50sm889956plb.286.2024.04.18.01.00.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 01:00:11 -0700 (PDT) From: Manivannan Sadhasivam Date: Thu, 18 Apr 2024 13:29:59 +0530 Subject: [PATCH v2 2/2] PCI: endpoint: pci-epf-test: Use 'msix_capable' flag directly in pci_epf_test_alloc_space() Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240418-pci-epf-test-fix-v2-2-eacd54831444@linaro.org> References: <20240418-pci-epf-test-fix-v2-0-eacd54831444@linaro.org> In-Reply-To: <20240418-pci-epf-test-fix-v2-0-eacd54831444@linaro.org> To: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Lorenzo Pieralisi Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Niklas Cassel , Manivannan Sadhasivam X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=1427; i=manivannan.sadhasivam@linaro.org; h=from:subject:message-id; bh=dx7Pu4GSAq806/2nc7mcGWRQfuaNyNK4rj6uW2+wJD8=; b=owEBbQGS/pANAwAKAVWfEeb+kc71AcsmYgBmINMA5+bqKFZPvbU7DVk3Jfh5SvPNaW0wC9WR1 0WC1DukO3+JATMEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCZiDTAAAKCRBVnxHm/pHO 9aiiB/wIftcF3SlSCrP5fsOjH8SZ+x/gtt40KoKbiXqD56t8qWPVnQBWt/suyD/M6TloYwe3/ZF x5EIJ3PG0zDzrBXsUXc0XlenBWMUbopvYoIEgjPbWvrdp+B/Gf2GGOj0euZ5a/B0Wi2Q6M+DF5s mHfACMhqiDJrJoxuN/zNSD5MhkEorgTa2wiik19zGMPlJrOu01O9PXNdRZZb/6fRH7DSpRlVgMm Q8tDyrckS+CWdlvuDYwYWfNNmcJt1BM9wPrgFvzSsKrf2ActOoF+BbelsHGDcJMEk/xXjcuha72 W9xfYcG7ulee2XdrbcKzmsxuB1VP9mmzSdKrkAYfVtIVRY0Y X-Developer-Key: i=manivannan.sadhasivam@linaro.org; a=openpgp; fpr=C668AEC3C3188E4C611465E7488550E901166008 Instead of using a local variable to cache the 'msix_capable' flag, use it directly to simplify the code. Suggested-by: Niklas Cassel Signed-off-by: Manivannan Sadhasivam Reviewed-by: Niklas Cassel Reviewed-by: Frank Li --- drivers/pci/endpoint/functions/pci-epf-test.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 546d2a27955c..3de18a601e7b 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -802,19 +802,15 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) size_t msix_table_size = 0; size_t test_reg_bar_size; size_t pba_size = 0; - bool msix_capable; void *base; enum pci_barno test_reg_bar = epf_test->test_reg_bar; enum pci_barno bar; - const struct pci_epc_features *epc_features; + const struct pci_epc_features *epc_features = epf_test->epc_features; size_t test_reg_size; - epc_features = epf_test->epc_features; - test_reg_bar_size = ALIGN(sizeof(struct pci_epf_test_reg), 128); - msix_capable = epc_features->msix_capable; - if (msix_capable) { + if (epc_features->msix_capable) { msix_table_size = PCI_MSIX_ENTRY_SIZE * epf->msix_interrupts; epf_test->msix_table_offset = test_reg_bar_size; /* Align to QWORD or 8 Bytes */