From 29091a80b693e679e5283326e921d21d04c6bcbb Mon Sep 17 00:00:00 2001
From: Federico Vaga <federico.vaga@gmail.com>
Date: Mon, 13 Feb 2012 15:17:19 +0100
Subject: [PATCH] zattr_show: check if zattr->s_op are present

If a zio object declares a set of read only attributes and it doesn't
need s_op->info_get(), it can avoid the s_op assignment, so zattr_show
now checks if s_op is defined before calling it.

Signed-off-by: Federico Vaga <federico.vaga@gmail.com>
Acked-by: Alessandro Rubini <rubini@gnudd.com>
---
 zio-sys.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/zio-sys.c b/zio-sys.c
index f0949aa..7690902 100644
--- a/zio-sys.c
+++ b/zio-sys.c
@@ -698,6 +698,9 @@ static ssize_t zattr_show(struct kobject *kobj, struct attribute *attr,
 		return sprintf(buf, "%d\n",
 			  !((*__get_flag(to_zio_head(kobj))) & ZIO_DISABLED));
 
+	/* only read attributes can avoid s_op declaration */
+	if (!zattr->s_op)
+		goto out;
 	if (zattr->s_op->info_get) {
 		lock = __get_spinlock(to_zio_head(kobj));
 		spin_lock(lock);
@@ -706,6 +709,7 @@ static ssize_t zattr_show(struct kobject *kobj, struct attribute *attr,
 		if (err)
 			return err;
 	}
+out:
 	len = sprintf(buf, "%i\n", zattr->value);
 	return len;
 }
-- 
GitLab