From: Sean Anderson <seanga2@gmail.com>
To: "David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org
Cc: Nick Bowler <nbowler@draconx.ca>,
Rolf Eike Beer <eike-kernel@sf-tec.de>,
Zheyu Ma <zheyuma97@gmail.com>,
linux-kernel@vger.kernel.org (open list),
Sean Anderson <seanga2@gmail.com>
Subject: [PATCH net-next v2 04/13] sunhme: Return an ERR_PTR from quattro_pci_find
Date: Fri, 23 Sep 2022 21:53:30 -0400 [thread overview]
Message-ID: <20220924015339.1816744-5-seanga2@gmail.com> (raw)
In-Reply-To: <20220924015339.1816744-1-seanga2@gmail.com>
In order to differentiate between a missing bridge and an OOM condition,
return ERR_PTRs from quattro_pci_find. This also does some general linting
in the area.
Signed-off-by: Sean Anderson <seanga2@gmail.com>
---
Changes in v2:
- Use memset to clear p->happy_meals
drivers/net/ethernet/sun/sunhme.c | 49 +++++++++++++++++--------------
1 file changed, 27 insertions(+), 22 deletions(-)
diff --git a/drivers/net/ethernet/sun/sunhme.c b/drivers/net/ethernet/sun/sunhme.c
index 63a7cacd8286..b0843210beb9 100644
--- a/drivers/net/ethernet/sun/sunhme.c
+++ b/drivers/net/ethernet/sun/sunhme.c
@@ -2498,18 +2498,16 @@ static struct quattro *quattro_sbus_find(struct platform_device *child)
return qp;
qp = kmalloc(sizeof(struct quattro), GFP_KERNEL);
- if (qp != NULL) {
- int i;
+ if (!qp)
+ return NULL;
- for (i = 0; i < 4; i++)
- qp->happy_meals[i] = NULL;
+ memset(qp->happy_meals, 0, sizeof(*qp->happy_meals));
- qp->quattro_dev = child;
- qp->next = qfe_sbus_list;
- qfe_sbus_list = qp;
+ qp->quattro_dev = child;
+ qp->next = qfe_sbus_list;
+ qfe_sbus_list = qp;
- platform_set_drvdata(op, qp);
- }
+ platform_set_drvdata(op, qp);
return qp;
}
@@ -2569,30 +2567,33 @@ static void quattro_sbus_free_irqs(void)
#ifdef CONFIG_PCI
static struct quattro *quattro_pci_find(struct pci_dev *pdev)
{
+ int i;
struct pci_dev *bdev = pdev->bus->self;
struct quattro *qp;
- if (!bdev) return NULL;
+ if (!bdev)
+ return ERR_PTR(-ENODEV);
+
for (qp = qfe_pci_list; qp != NULL; qp = qp->next) {
struct pci_dev *qpdev = qp->quattro_dev;
if (qpdev == bdev)
return qp;
}
+
qp = kmalloc(sizeof(struct quattro), GFP_KERNEL);
- if (qp != NULL) {
- int i;
+ if (!qp)
+ return ERR_PTR(-ENOMEM);
- for (i = 0; i < 4; i++)
- qp->happy_meals[i] = NULL;
+ for (i = 0; i < 4; i++)
+ qp->happy_meals[i] = NULL;
- qp->quattro_dev = bdev;
- qp->next = qfe_pci_list;
- qfe_pci_list = qp;
+ qp->quattro_dev = bdev;
+ qp->next = qfe_pci_list;
+ qfe_pci_list = qp;
- /* No range tricks necessary on PCI. */
- qp->nranges = 0;
- }
+ /* No range tricks necessary on PCI. */
+ qp->nranges = 0;
return qp;
}
#endif /* CONFIG_PCI */
@@ -2948,11 +2949,15 @@ static int happy_meal_pci_probe(struct pci_dev *pdev,
if (!strcmp(prom_name, "SUNW,qfe") || !strcmp(prom_name, "qfe")) {
qp = quattro_pci_find(pdev);
- if (qp == NULL)
+ if (IS_ERR(qp)) {
+ err = PTR_ERR(qp);
goto err_out;
+ }
+
for (qfe_slot = 0; qfe_slot < 4; qfe_slot++)
- if (qp->happy_meals[qfe_slot] == NULL)
+ if (!qp->happy_meals[qfe_slot])
break;
+
if (qfe_slot == 4)
goto err_out;
}
--
2.37.1
next prev parent reply other threads:[~2022-09-24 1:54 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-24 1:53 [PATCH net-next v2 00/13] net: sunhme: Cleanups and logging improvements Sean Anderson
2022-09-24 1:53 ` [PATCH net-next v2 01/13] sunhme: remove unused tx_dump_ring() Sean Anderson
2022-09-24 1:53 ` [PATCH net-next v2 02/13] sunhme: Remove version Sean Anderson
2022-09-24 1:53 ` [PATCH net-next v2 03/13] sunhme: forward the error code from pci_enable_device() Sean Anderson
2022-09-24 1:53 ` Sean Anderson [this message]
2022-09-24 1:53 ` [PATCH net-next v2 05/13] sunhme: Regularize probe errors Sean Anderson
2022-09-24 1:53 ` [PATCH net-next v2 06/13] sunhme: switch to devres Sean Anderson
2022-09-24 1:53 ` [PATCH net-next v2 07/13] sunhme: Convert FOO((...)) to FOO(...) Sean Anderson
2022-09-27 7:58 ` David Laight
2022-09-27 13:57 ` Sean Anderson
2022-09-24 1:53 ` [PATCH net-next v2 08/13] sunhme: Clean up debug infrastructure Sean Anderson
2022-09-24 1:53 ` [PATCH net-next v2 09/13] sunhme: Convert printk(KERN_FOO ...) to pr_foo(...) Sean Anderson
2022-09-24 1:53 ` [PATCH net-next v2 10/13] sunhme: Use (net)dev_foo wherever possible Sean Anderson
2022-09-24 1:53 ` [PATCH net-next v2 11/13] sunhme: Combine continued messages Sean Anderson
2022-09-24 1:53 ` [PATCH net-next v2 12/13] sunhme: Use vdbg for spam-y prints Sean Anderson
2022-09-24 1:53 ` [PATCH net-next v2 13/13] sunhme: Add myself as a maintainer Sean Anderson
2022-09-27 0:50 ` [PATCH net-next v2 00/13] net: sunhme: Cleanups and logging improvements patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220924015339.1816744-5-seanga2@gmail.com \
--to=seanga2@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=eike-kernel@sf-tec.de \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nbowler@draconx.ca \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=zheyuma97@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox