All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Snook <csnook@redhat.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Jay Cliburn <jacliburn@bellsouth.net>,
	jeff@garzik.org, shemminger@osdl.org, romieu@fr.zoreil.com,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/4] atl1: Main C file for Attansic L1 driver
Date: Mon, 20 Nov 2006 01:12:57 -0500	[thread overview]
Message-ID: <45614769.4020005@redhat.com> (raw)
In-Reply-To: <200611200057.45274.arnd@arndb.de>

Arnd Bergmann wrote:
> On Sunday 19 November 2006 21:30, Jay Cliburn wrote:
>> This patch contains the main C file for the Attansic L1 gigabit ethernet
>> adapter driver.
> 
> Just a few style comments:
> 
>> +	/* PCI config space info */
>> +	hw->vendor_id = pdev->vendor;
>> +	hw->device_id = pdev->device;
>> +	hw->subsystem_vendor_id = pdev->subsystem_vendor;
>> +	hw->subsystem_id = pdev->subsystem_device;
> 
> Do you actually need the copies of these fields? I guess you can
> always access the data from pdev.

Probably not.  Thanks for pointing this out.

>> +	size = sizeof(struct at_buffer) * (tpd_ring->count + rfd_ring->count);
>> +	tpd_ring->buffer_info = kmalloc(size, GFP_KERNEL);
>> +	if (unlikely(!tpd_ring->buffer_info)) {
>> +		printk(KERN_WARNING "%s: kmalloc failed , size = D%d\n", 
>> +			at_driver_name, size);
>> +		return -ENOMEM;
>> +	}
>> +	rfd_ring->buffer_info =
>> +	    (struct at_buffer *)(tpd_ring->buffer_info + tpd_ring->count);
>> +
>> +	memset(tpd_ring->buffer_info, 0, size);
> 
> Use kzalloc or kcalloc here.

Good point.  I guess we should check the whole driver over for that.

>> +	ring_header->desc =
>> +	    pci_alloc_consistent(pdev, ring_header->size, &ring_header->dma);
>> +	if (unlikely(!ring_header->desc)) {
>> +		kfree(tpd_ring->buffer_info);
>> +		printk(KERN_WARNING 
>> +			"%s: pci_alloc_consistent failed, size = D%d\n", 
>> +			at_driver_name, size);
>> +		return -ENOMEM;
>> +	}
> 
> Your cleanup path gets simpler if you use goto, and only one
> instance of kfree at the end, instead of multiple return statements
> in this function.
> 
> 
>> +	while (!buffer_info->alloced && !next_info->alloced) {
>> +		if (NULL != buffer_info->skb) {
>> +			buffer_info->alloced = 1;
>> +			goto next;
>> +		}
> 
> Instead of 'if (NULL != buffer_info->skb)', you should write
> 'if (buffer_info->skb)', like you do elsewhere.

Thanks for pointing this out.  Seeing as this code is a ripoff of e1000, 
hacked up by Attansic, and then heavily reworked by Jay and I, there are 
some stylistic differences, but we'll try to make it more consistent.

>> +	      next:
>> +		rfd_next_to_use = next_next;
>> +		if (unlikely(++next_next == rfd_ring->count))
>> +			next_next = 0;
> 
> Labels go to the start of a line.

I blame Attansic.

>> +#ifdef NETIF_F_HW_VLAN_TX
>> +		if (adapter->vlgrp && (rrd->pkt_flg & PACKET_FLAG_VLAN_INS)) {
>> +			u16 vlan_tag = (rrd->vlan_tag >> 4) |
>> +			    		((rrd->vlan_tag & 7) << 13) | 
>> +					((rrd->vlan_tag & 8) << 9);
>> +			vlan_hwaccel_rx(skb, adapter->vlgrp, vlan_tag);
>> +		} else
>> +#endif
> 
> No need for the #ifdef when submitting the driver for inclusion.
> In this kernel version, NETIF_F_HW_VLAN_TX is always defined.

Thanks.  There are a lot of ifdefs that we're not sure are always 
defined.  Removing those would make this code much easier to review. 
More eyes on those ifdefs would be appreciated.

>> +static int at_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
>> +{
>> +	struct at_adapter *adapter = netdev_priv(netdev);
>> +/*	struct mii_ioctl_data *data = (struct mii_ioctl_data *)&ifr->ifr_data;*/
>> +	struct mii_ioctl_data *data = if_mii(ifr);
>> +	unsigned long flags;
>> +
>> +	switch (cmd) {
>> +	case SIOCGMIIPHY:
>> +		data->phy_id = 0;
>> +		break;
>> +	case SIOCGMIIREG:
>> +		if (!capable(CAP_NET_ADMIN))
>> +			return -EPERM;
>> +		spin_lock_irqsave(&adapter->stats_lock, flags);
>> +		if (at_read_phy_reg
>> +		    (&adapter->hw, data->reg_num & 0x1F, &data->val_out)) {
>> +			spin_unlock_irqrestore(&adapter->stats_lock, flags);
>> +			return -EIO;
>> +		}
>> +		spin_unlock_irqrestore(&adapter->stats_lock, flags);
>> +		break;
>> +	case SIOCSMIIREG:
>> +		if (!capable(CAP_NET_ADMIN))
>> +			return -EPERM;
>> +		if (data->reg_num & ~(0x1F))
>> +			return -EFAULT;
>> +		spin_lock_irqsave(&adapter->stats_lock, flags);
>> +		printk(KERN_DEBUG "%s: at_mii_ioctl write %x %x\n", 
>> +			at_driver_name, data->reg_num,
>> +			  data->val_in);
>> +		if (at_write_phy_reg(&adapter->hw, data->reg_num, data->val_in)) {
>> +			spin_unlock_irqrestore(&adapter->stats_lock, flags);
>> +			return -EIO;
>> +		}
>> +		spin_unlock_irqrestore(&adapter->stats_lock, flags);
>> +		break;
>> +	default:
>> +		return -EOPNOTSUPP;
>> +	}
>> +	return AT_SUCCESS;
>> +}
>> +#endif				/* SIOCGMIIPHY */
> 
> Any reason why you can't use generic_mii_ioctl?

I decided to mostly leave this code alone, in the hope that we could 
just rip out MII support entirely and nobody would mind.  What do you think?

	-- Chris

>> +      err_init_hw:
>> +      err_reset:
>> +      err_register:
>> +      err_sw_init:
>> +      err_eeprom:
>> +	iounmap(adapter->hw.hw_addr);
>> +      err_ioremap:
>> +	free_netdev(netdev);
>> +      err_alloc_etherdev:
>> +	pci_release_regions(pdev);
>> +	return err;
> 
> It's more common to have a single label with multiple gotos instead
> of multiple labels that all go to one statement.


  reply	other threads:[~2006-11-20  6:14 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-19 20:30 [PATCH 3/4] atl1: Main C file for Attansic L1 driver Jay Cliburn
2006-11-19 21:46 ` Jan Engelhardt
2006-11-19 23:57 ` Arnd Bergmann
2006-11-20  6:12   ` Chris Snook [this message]
2006-11-20 12:21     ` Arnd Bergmann
2006-11-20 18:02       ` Stephen Hemminger
2006-11-20 19:35         ` Jeff Garzik
2006-11-20 20:15           ` Stephen Hemminger
2006-11-20 21:36             ` Jeff Garzik
2006-11-20 21:59               ` Stephen Hemminger
2006-11-20 22:04                 ` Jeff Garzik
2006-11-20 23:17                   ` Stephen Hemminger
2006-11-20 12:39 ` Chris Snook
  -- strict thread matches above, loose matches on Subject: below --
2007-01-11  0:42 Jay Cliburn
2007-01-11  9:33 ` Christoph Hellwig
2007-01-21 21:06 Jay Cliburn
2007-01-22  8:22 ` Arjan van de Ven
2007-01-22 16:48   ` Jay Cliburn

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=45614769.4020005@redhat.com \
    --to=csnook@redhat.com \
    --cc=arnd@arndb.de \
    --cc=jacliburn@bellsouth.net \
    --cc=jeff@garzik.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=romieu@fr.zoreil.com \
    --cc=shemminger@osdl.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.