[PATCH] edd: consolidate error checks
From: Akinobu Mita
Date: Fri May 23 2008 - 22:16:57 EST
Many show operations in edd_attribute have same error checks at the head.
This patch consolidates these error checks to callee function.
Signed-off-by: Akinobu Mita <akinobu.mita@xxxxxxxxx>
Cc: Matt Domsch <Matt_Domsch@xxxxxxxx>
---
drivers/firmware/edd.c | 74 ++++++++++++++++++++-----------------------------
1 file changed, 31 insertions(+), 43 deletions(-)
Index: 2.6-git/drivers/firmware/edd.c
===================================================================
--- 2.6-git.orig/drivers/firmware/edd.c
+++ 2.6-git/drivers/firmware/edd.c
@@ -115,11 +115,14 @@ edd_attr_show(struct kobject * kobj, str
{
struct edd_device *dev = to_edd_device(kobj);
struct edd_attribute *edd_attr = to_edd_attr(attr);
- ssize_t ret = -EIO;
- if (edd_attr->show)
- ret = edd_attr->show(dev, buf);
- return ret;
+ if (!edd_attr->show)
+ return -EIO;
+
+ if (!dev || !buf)
+ return -EINVAL;
+
+ return edd_attr->show(dev, buf);
}
static struct sysfs_ops edd_attr_ops = {
@@ -133,10 +136,8 @@ edd_show_host_bus(struct edd_device *ede
char *p = buf;
int i;
- if (!edev)
- return -EINVAL;
info = edd_dev_get_info(edev);
- if (!info || !buf)
+ if (!info)
return -EINVAL;
for (i = 0; i < 4; i++) {
@@ -179,10 +180,8 @@ edd_show_interface(struct edd_device *ed
char *p = buf;
int i;
- if (!edev)
- return -EINVAL;
info = edd_dev_get_info(edev);
- if (!info || !buf)
+ if (!info)
return -EINVAL;
for (i = 0; i < 8; i++) {
@@ -243,10 +242,9 @@ edd_show_raw_data(struct edd_device *ede
{
struct edd_info *info;
ssize_t len = sizeof (info->params);
- if (!edev)
- return -EINVAL;
+
info = edd_dev_get_info(edev);
- if (!info || !buf)
+ if (!info)
return -EINVAL;
if (!(info->params.key == 0xBEDD || info->params.key == 0xDDBE))
@@ -265,10 +263,9 @@ edd_show_version(struct edd_device *edev
{
struct edd_info *info;
char *p = buf;
- if (!edev)
- return -EINVAL;
+
info = edd_dev_get_info(edev);
- if (!info || !buf)
+ if (!info)
return -EINVAL;
p += scnprintf(p, left, "0x%02x\n", info->version);
@@ -288,10 +285,9 @@ edd_show_extensions(struct edd_device *e
{
struct edd_info *info;
char *p = buf;
- if (!edev)
- return -EINVAL;
+
info = edd_dev_get_info(edev);
- if (!info || !buf)
+ if (!info)
return -EINVAL;
if (info->interface_support & EDD_EXT_FIXED_DISK_ACCESS) {
@@ -314,10 +310,9 @@ edd_show_info_flags(struct edd_device *e
{
struct edd_info *info;
char *p = buf;
- if (!edev)
- return -EINVAL;
+
info = edd_dev_get_info(edev);
- if (!info || !buf)
+ if (!info)
return -EINVAL;
if (info->params.info_flags & EDD_INFO_DMA_BOUNDARY_ERROR_TRANSPARENT)
@@ -344,10 +339,9 @@ edd_show_legacy_max_cylinder(struct edd_
{
struct edd_info *info;
char *p = buf;
- if (!edev)
- return -EINVAL;
+
info = edd_dev_get_info(edev);
- if (!info || !buf)
+ if (!info)
return -EINVAL;
p += snprintf(p, left, "%u\n", info->legacy_max_cylinder);
@@ -359,10 +353,9 @@ edd_show_legacy_max_head(struct edd_devi
{
struct edd_info *info;
char *p = buf;
- if (!edev)
- return -EINVAL;
+
info = edd_dev_get_info(edev);
- if (!info || !buf)
+ if (!info)
return -EINVAL;
p += snprintf(p, left, "%u\n", info->legacy_max_head);
@@ -374,10 +367,9 @@ edd_show_legacy_sectors_per_track(struct
{
struct edd_info *info;
char *p = buf;
- if (!edev)
- return -EINVAL;
+
info = edd_dev_get_info(edev);
- if (!info || !buf)
+ if (!info)
return -EINVAL;
p += snprintf(p, left, "%u\n", info->legacy_sectors_per_track);
@@ -389,10 +381,9 @@ edd_show_default_cylinders(struct edd_de
{
struct edd_info *info;
char *p = buf;
- if (!edev)
- return -EINVAL;
+
info = edd_dev_get_info(edev);
- if (!info || !buf)
+ if (!info)
return -EINVAL;
p += scnprintf(p, left, "%u\n", info->params.num_default_cylinders);
@@ -404,10 +395,9 @@ edd_show_default_heads(struct edd_device
{
struct edd_info *info;
char *p = buf;
- if (!edev)
- return -EINVAL;
+
info = edd_dev_get_info(edev);
- if (!info || !buf)
+ if (!info)
return -EINVAL;
p += scnprintf(p, left, "%u\n", info->params.num_default_heads);
@@ -419,10 +409,9 @@ edd_show_default_sectors_per_track(struc
{
struct edd_info *info;
char *p = buf;
- if (!edev)
- return -EINVAL;
+
info = edd_dev_get_info(edev);
- if (!info || !buf)
+ if (!info)
return -EINVAL;
p += scnprintf(p, left, "%u\n", info->params.sectors_per_track);
@@ -434,10 +423,9 @@ edd_show_sectors(struct edd_device *edev
{
struct edd_info *info;
char *p = buf;
- if (!edev)
- return -EINVAL;
+
info = edd_dev_get_info(edev);
- if (!info || !buf)
+ if (!info)
return -EINVAL;
p += scnprintf(p, left, "%llu\n", info->params.number_of_sectors);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/