From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: Jaccon Bastiaansen <jaccon.bastiaansen@gmail.com>
Cc: s.hauer@pengutronix.de, kernel@pengutronix.de,
u.kleine-koenig@pengutronix.de, davem@davemloft.net,
cavokz@gmail.com, netdev@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH V3 1/4] CS89x0 : add platform driver support
Date: Mon, 16 Jan 2012 11:09:07 +0000 [thread overview]
Message-ID: <20120116110907.GU1068@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <1326570996-27818-1-git-send-email-jaccon.bastiaansen@gmail.com>
On Sat, Jan 14, 2012 at 08:56:36PM +0100, Jaccon Bastiaansen wrote:
> The CS89x0 ethernet controller is used on a number of evaluation
> boards, such as the MX31ADS. The current driver has memory address and
> IRQ settings for each board on which this controller is used. Driver
> updates are therefore required to support other boards that also use
> the CS89x0. To avoid these driver updates, a better mechanism
> (platform driver support) is added to communicate the board dependent
> settings to the driver.
Please check your changes with sparse and checkpatch.
> @@ -236,6 +243,11 @@ struct net_local {
> unsigned char *end_dma_buff; /* points to the end of the buffer */
> unsigned char *rx_dma_ptr; /* points to the next packet */
> #endif
> +#ifdef CONFIG_CS89x0_PLATFORM
> + void *virt_addr; /* Virtual address for accessing the CS89x0. */
void __iomem *virt_addr;
> +#ifdef CONFIG_CS89x0_PLATFORM
> +static int __init cs89x0_platform_probe(struct platform_device *pdev)
> +{
> + struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
> + struct net_local *lp = netdev_priv(dev);
> + struct resource *mem_res;
> + int err;
> +
> + if (!dev)
> + return -ENODEV;
Wouldn't -ENOMEM be better? Also, organise this as:
struct net_device *dev = alloc_etherdev(sizeof(struct net_local));
struct net_local *lp;
if (!dev)
return -ENOMEM;
lp = netdev_priv(dev);
because you don't shouldn't how netdev_priv() works, or whether it
dereferences a pointer within the net_device. (How netdev_priv()
works is not something that should concern you as a driver writer -
it's there to hide the details, which may change over time.)
> +
> + mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + dev->irq = platform_get_irq(pdev, 0);
> + if (mem_res == NULL || dev->irq <= 0) {
> + dev_warn(&dev->dev, "memory/interrupt resource missing.\n");
> + err = -ENOENT;
Other patches return -ENXIO for this.
> + goto free;
> + }
> +
> + lp->phys_addr = mem_res->start;
> + lp->size = mem_res->end - mem_res->start + 1;
lp->size = resource_size(mem_res);
> + if (!request_mem_region(lp->phys_addr, lp->size, DRV_NAME)) {
> + dev_warn(&dev->dev, "request_mem_region() failed.\n");
> + err = -ENOMEM;
If the region is busy, then this fails. It's return value should therefore
be -EBUSY.
> + goto free;
> + }
> +
> + lp->virt_addr = ioremap(lp->phys_addr, lp->size);
> + if (!lp->virt_addr) {
> + dev_warn(&dev->dev, "ioremap() failed.\n");
> + err = -ENOMEM;
> + goto release;
> + }
> +
> + err = cs89x0_probe1(dev, (int)lp->virt_addr, 0);
Have you checked whether this causes a compiler warning? Normally if you
cast a pointer to 'int', it'll complain about a narrowing cast.
There are architectures Linux supports where int is 32-bit and a pointer
is 64-bit, so this won't work. It needs the 'port' type changed to
something which pointers can be casted (I suggest unsigned long, as we
do elsewhere.)
next prev parent reply other threads:[~2012-01-16 11:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-14 19:56 [PATCH V3 1/4] CS89x0 : add platform driver support Jaccon Bastiaansen
2012-01-16 10:46 ` Sascha Hauer
2012-01-16 11:09 ` Russell King - ARM Linux [this message]
2012-01-17 17:39 ` David Miller
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=20120116110907.GU1068@n2100.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=cavokz@gmail.com \
--cc=davem@davemloft.net \
--cc=jaccon.bastiaansen@gmail.com \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=netdev@vger.kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=u.kleine-koenig@pengutronix.de \
/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).