linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Philipp Ittershagen <lists@gate-nine.de>
To: harninder.rai@freescale.com
Cc: linuxppc-dev@lists.ozlabs.org,
	Vivek Mahajan <vivek.mahajan@freescale.com>
Subject: Re: [PATCH][v1] powerpc/fsl: 85xx: add cache-sram support
Date: Wed, 13 Oct 2010 12:10:40 +0200	[thread overview]
Message-ID: <1286964640.16168.8.camel@peter.localdomain> (raw)
In-Reply-To: <1286961435-3010-1-git-send-email-harninder.rai@freescale.com>

Hi Harninder,

On Wed, 2010-10-13 at 14:47 +0530, harninder.rai@freescale.com wrote:
> +int __init instantiate_cache_sram(struct platform_device *dev,
> +		struct sram_parameters sram_params)
> +{
> +	if (cache_sram) {
> +		dev_err(&dev->dev, "Already initialized cache-sram\n");
> +		return -EBUSY;
> +	}
> +
> +	cache_sram = kzalloc(sizeof(struct mpc85xx_cache_sram), GFP_KERNEL);
> +	if (!cache_sram) {
> +		dev_err(&dev->dev, "Out of memory for cache_sram structure\n");
> +		return -ENOMEM;
> +	}
> +
> +	cache_sram->base_phys = sram_params.sram_offset;
> +	cache_sram->size = sram_params.sram_size;
> +
> +	if (!request_mem_region(cache_sram->base_phys, cache_sram->size,
> +						"fsl_85xx_cache_sram")) {
> +		dev_err(&dev->dev, "%s: request memory failed\n",
> +				dev->dev.of_node->full_name);
> +		kfree(cache_sram);
> +		return -ENXIO;
> +	}
> +
> +	cache_sram->base_virt = ioremap_flags(cache_sram->base_phys,
> +				cache_sram->size, _PAGE_COHERENT | PAGE_KERNEL);
> +	if (!cache_sram->base_virt) {
> +		dev_err(&dev->dev, "%s: ioremap_flags failed\n",
> +				dev->dev.of_node->full_name);
> +		release_mem_region(cache_sram->base_phys, cache_sram->size);
> +		kfree(cache_sram);
> +		return -ENOMEM;
> +	}
> +
> +	cache_sram->rh = rh_create(sizeof(unsigned int));
> +	if (IS_ERR(cache_sram->rh)) {
> +		dev_err(&dev->dev, "%s: Unable to create remote heap\n",
> +				dev->dev.of_node->full_name);
> +		iounmap(cache_sram->base_virt);
> +		release_mem_region(cache_sram->base_phys, cache_sram->size);
> +		kfree(cache_sram);
> +		return PTR_ERR(cache_sram->rh);
> +	}
> +
> +	rh_attach_region(cache_sram->rh, 0, cache_sram->size);
> +	spin_lock_init(&cache_sram->lock);
> +
> +	dev_info(&dev->dev, "[base:0x%llx, size:0x%x] configured and loaded\n",
> +		(unsigned long long)cache_sram->base_phys, cache_sram->size);
> +	return 0;
> +}

You could save some redundant code by using goto statements for error
handling.

For example:

...

int ret;

if (!request_mem_region(...)) {
	ret = -ENXIO;
	goto out_free;
}


if (!ioremap(...)) {
	ret = -ENOMEM;
	goto out_release;
}

if (!IS_ERR(cache_sram->rh)) {
	ret = PTR_ERR(...);
	goto out_unmap;
}

...

return 0;

out_unmap:
	iounmap(...);
out_release:
	release_mem_region(...);
out_free:
	kfree(...);
	return ret;
}



-- Philipp

      reply	other threads:[~2010-10-13 10:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-13  9:17 [PATCH][v1] powerpc/fsl: 85xx: add cache-sram support harninder.rai
2010-10-13 10:10 ` Philipp Ittershagen [this message]

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=1286964640.16168.8.camel@peter.localdomain \
    --to=lists@gate-nine.de \
    --cc=harninder.rai@freescale.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=vivek.mahajan@freescale.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).