netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Anderson <seanga2@gmail.com>
To: Rolf Eike Beer <eike-kernel@sf-tec.de>,
	"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: linux-kernel@vger.kernel.org, Zheyu Ma <zheyuma97@gmail.com>,
	Nick Bowler <nbowler@draconx.ca>
Subject: Re: [PATCH net-next 04/13] sunhme: Return an ERR_PTR from quattro_pci_find
Date: Mon, 19 Sep 2022 10:08:55 -0400	[thread overview]
Message-ID: <0ffba41b-3808-c2d8-e180-d865c8d5d306@gmail.com> (raw)
In-Reply-To: <14346017.muaEW6z1dk@eto.sf-tec.de>

On 9/19/22 09:11, Rolf Eike Beer wrote:
> Am Montag, 19. September 2022, 01:26:17 CEST schrieb Sean Anderson:
>> 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>
>> ---
>>
>>   drivers/net/ethernet/sun/sunhme.c | 33 +++++++++++++++++++------------
>>   1 file changed, 20 insertions(+), 13 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/sun/sunhme.c
>> b/drivers/net/ethernet/sun/sunhme.c index 1fc16801f520..52247505d08e 100644
>> --- a/drivers/net/ethernet/sun/sunhme.c
>> +++ b/drivers/net/ethernet/sun/sunhme.c
>> @@ -2569,30 +2569,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;
> 
> I know you are only reindenting it, but I dislike moving the variable up to
> the top of the function. Since the kernel is C99 meanwhile the variable could
> be declared just in the for loop. 

Hm, I thought this style was discouraged.

> And when touching this anyway I think we
> could get rid of the magic "4" by using ARRAY_SIZE(qp->happy_meals). Or just
> replace the whole thing with memset(qp->happy_meals, 0, sizeof(qp-
>> happy_meals)).

Yeah, that avoids the whole problem.

--Sean


  reply	other threads:[~2022-09-19 14:09 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-18 23:26 [PATCH net-next 00/13] net: sunhme: Cleanups and logging improvements Sean Anderson
2022-09-18 23:26 ` [PATCH net-next 01/13] sunhme: remove unused tx_dump_ring() Sean Anderson
2022-09-18 23:26 ` [PATCH net-next 02/13] sunhme: Remove version Sean Anderson
2022-09-18 23:26 ` [PATCH net-next 03/13] sunhme: forward the error code from pci_enable_device() Sean Anderson
2022-09-20 19:37   ` Jakub Kicinski
2022-09-18 23:26 ` [PATCH net-next 04/13] sunhme: Return an ERR_PTR from quattro_pci_find Sean Anderson
2022-09-19 13:11   ` Rolf Eike Beer
2022-09-19 14:08     ` Sean Anderson [this message]
2022-09-20 19:36   ` Jakub Kicinski
2022-09-18 23:26 ` [PATCH net-next 05/13] sunhme: Regularize probe errors Sean Anderson
2022-09-20 19:36   ` Jakub Kicinski
2022-09-18 23:26 ` [PATCH net-next 06/13] sunhme: switch to devres Sean Anderson
2022-09-18 23:26 ` [PATCH net-next 07/13] sumhme: Convert FOO((...)) to FOO(...) Sean Anderson
2022-09-18 23:26 ` [PATCH net-next 08/13] sunhme: Clean up debug infrastructure Sean Anderson
2022-09-18 23:26 ` [PATCH net-next 09/13] sunhme: Convert printk(KERN_FOO ...) to pr_foo(...) Sean Anderson
2022-09-18 23:26 ` [PATCH net-next 10/13] sunhme: Use (net)dev_foo wherever possible Sean Anderson
2022-09-18 23:26 ` [PATCH net-next 11/13] sunhme: Combine continued messages Sean Anderson
2022-09-19 13:23   ` Rolf Eike Beer
2022-09-19 14:14     ` Sean Anderson
2022-09-18 23:26 ` [PATCH net-next 12/13] sunhme: Use vdbg for spam-y prints Sean Anderson
2022-09-18 23:26 ` [PATCH net-next 13/13] sunhme: Add myself as a maintainer Sean Anderson

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=0ffba41b-3808-c2d8-e180-d865c8d5d306@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;
as well as URLs for NNTP newsgroup(s).