From: Alexander Schmidt <[EMAIL PROTECTED]>

The backport kobject.h was causing an include recursion (included slab.h
which in turn needed kobject.h), so move the function bodies to their own .c
file in core, which is the only place where the new functions are needed.

Signed-off-by: Joachim Fenkes <[EMAIL PROTECTED]>
---
 .../backport/2.6.24/include/linux/kobject.h        |  134 +---------------
 .../backport/2.6.24/core_1_kobject_backport.patch  |  175 ++++++++++++++++++++
 2 files changed, 178 insertions(+), 131 deletions(-)
 create mode 100644 kernel_patches/backport/2.6.24/core_1_kobject_backport.patch

diff --git a/kernel_addons/backport/2.6.24/include/linux/kobject.h 
b/kernel_addons/backport/2.6.24/include/linux/kobject.h
index 3b842f4..f23d141 100644
--- a/kernel_addons/backport/2.6.24/include/linux/kobject.h
+++ b/kernel_addons/backport/2.6.24/include/linux/kobject.h
@@ -1,57 +1,8 @@
 #ifndef __BACKPORT_KOBJECT_H_TO_2_6_24__
 #define __BACKPORT_KOBJECT_H_TO_2_6_24__
 
-#include <linux/slab.h>
 #include_next <linux/kobject.h>
 
-struct kobj_attribute {
-       struct attribute attr;
-       ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,
-                       char *buf);
-       ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
-                        const char *buf, size_t count);
-};
-
-/* default kobject attribute operations */
-static ssize_t kobj_attr_show(struct kobject *kobj, struct attribute *attr,
-                             char *buf)
-{
-       struct kobj_attribute *kattr;
-       ssize_t ret = -EIO;
-
-       kattr = container_of(attr, struct kobj_attribute, attr);
-       if (kattr->show)
-               ret = kattr->show(kobj, kattr, buf);
-       return ret;
-}
-
-static ssize_t kobj_attr_store(struct kobject *kobj, struct attribute *attr,
-                              const char *buf, size_t count)
-{
-       struct kobj_attribute *kattr;
-       ssize_t ret = -EIO;
-
-       kattr = container_of(attr, struct kobj_attribute, attr);
-       if (kattr->store)
-               ret = kattr->store(kobj, kattr, buf, count);
-       return ret;
-}
-
-static struct sysfs_ops kobj_sysfs_ops = {
-       .show   = kobj_attr_show,
-       .store  = kobj_attr_store,
-};
-
-static void dynamic_kobj_release(struct kobject *kobj)
-{
-       pr_debug("kobject: (%p): %s\n", kobj, __FUNCTION__);
-       kfree(kobj);
-}
-
-static struct kobj_type dynamic_kobj_ktype = {
-       .release        = dynamic_kobj_release,
-       .sysfs_ops      = &kobj_sysfs_ops,
-};
 
 /**
  * kobject_create_and_add - create a struct kobject dynamically and register 
it with sysfs
@@ -66,39 +17,7 @@ static struct kobj_type dynamic_kobj_ktype = {
  *
  * If the kobject was not able to be created, NULL will be returned.
  */
-static inline struct kobject *kobject_create_and_add(const char *name, struct 
kobject *parent)
-{
-       struct kobject *kobj;
-       int retval;
-
-       kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
-       if (!kobj)
-               return NULL;
-
-       kobject_init(kobj);
-       kobj->ktype = &dynamic_kobj_ktype;
-       kobj->parent = parent;
-
-       retval = kobject_set_name(kobj, "%s", name);
-       if (retval) {
-               printk(KERN_WARNING "%s: kobject_set_name error: %d\n",
-                       __FUNCTION__, retval);
-               goto err;
-       }
-
-       retval = kobject_add(kobj);
-       if (retval) {
-               printk(KERN_WARNING "%s: kobject_add error: %d\n",
-                       __FUNCTION__, retval);
-               goto err;
-       }
-
-       return kobj;
-
-err:
-       kobject_put(kobj);
-       return NULL;
-}
+struct kobject *kobject_create_and_add(const char *name, struct kobject 
*parent);
 
 /**
  * kobject_init_and_add - initialize a kobject structure and add it to the 
kobject hierarchy
@@ -111,54 +30,7 @@ err:
  * kobject_add().  The same type of error handling after a call to
  * kobject_add() and kobject lifetime rules are the same here.
  */
-static int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
-                         struct kobject *parent, const char *fmt, ...)
-{
-       int retval;
-       int limit;
-       int need;
-       va_list args;
-       char *name;
-
-       /* find out how big a buffer we need */
-       name = kmalloc(1024, GFP_KERNEL);
-       if (!name) {
-               retval = -ENOMEM;
-               goto out;
-       }
-       va_start(args, fmt);
-       need = vsnprintf(name, 1024, fmt, args);
-       va_end(args);
-       kfree(name);
-
-       /* Allocate the new space and copy the string in */
-       limit = need + 1;
-       name = kmalloc(limit, GFP_KERNEL);
-       if (!name) {
-               retval = -ENOMEM;
-               goto out;
-       }
-
-       va_start(args, fmt);
-       need = vsnprintf(name, limit, fmt, args);
-       va_end(args);
-
-       kobject_init(kobj);
-
-       kobj->ktype = ktype;
-       kobj->parent = parent;
-
-       retval = kobject_set_name(kobj, name);
-       kfree(name);
-       if (retval)
-               goto out;
-
-       retval = kobject_add(kobj);
-       if (retval)
-               goto out;
-
-out:
-       return retval;
-}
+int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
+                         struct kobject *parent, const char *fmt, ...);
 
 #endif /* __BACKPORT_KOBJECT_H_TO_2_6_24__ */
diff --git a/kernel_patches/backport/2.6.24/core_1_kobject_backport.patch 
b/kernel_patches/backport/2.6.24/core_1_kobject_backport.patch
new file mode 100644
index 0000000..fa770e3
--- /dev/null
+++ b/kernel_patches/backport/2.6.24/core_1_kobject_backport.patch
@@ -0,0 +1,175 @@
+diff -Nurp ofa_kernel-1.4-orig/drivers/infiniband/core/kobject_backport.c 
ofa_kernel-1.4/drivers/infiniband/core/kobject_backport.c
+--- ofa_kernel-1.4-orig/drivers/infiniband/core/kobject_backport.c     
1970-01-01 01:00:00.000000000 +0100
++++ ofa_kernel-1.4/drivers/infiniband/core/kobject_backport.c  2008-07-11 
19:52:38.000000000 +0200
+@@ -0,0 +1,159 @@
++#include <linux/slab.h>
++
++struct kobj_attribute {
++      struct attribute attr;
++      ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,
++                      char *buf);
++      ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
++                       const char *buf, size_t count);
++};
++
++/* default kobject attribute operations */
++static ssize_t kobj_attr_show(struct kobject *kobj, struct attribute *attr,
++                            char *buf)
++{
++      struct kobj_attribute *kattr;
++      ssize_t ret = -EIO;
++
++      kattr = container_of(attr, struct kobj_attribute, attr);
++      if (kattr->show)
++              ret = kattr->show(kobj, kattr, buf);
++      return ret;
++}
++
++static ssize_t kobj_attr_store(struct kobject *kobj, struct attribute *attr,
++                             const char *buf, size_t count)
++{
++      struct kobj_attribute *kattr;
++      ssize_t ret = -EIO;
++
++      kattr = container_of(attr, struct kobj_attribute, attr);
++      if (kattr->store)
++              ret = kattr->store(kobj, kattr, buf, count);
++      return ret;
++}
++
++static struct sysfs_ops kobj_sysfs_ops = {
++      .show   = kobj_attr_show,
++      .store  = kobj_attr_store,
++};
++
++static void dynamic_kobj_release(struct kobject *kobj)
++{
++      pr_debug("kobject: (%p): %s\n", kobj, __FUNCTION__);
++      kfree(kobj);
++}
++
++static struct kobj_type dynamic_kobj_ktype = {
++      .release        = dynamic_kobj_release,
++      .sysfs_ops      = &kobj_sysfs_ops,
++};
++
++/**
++ * kobject_create_and_add - create a struct kobject dynamically and register 
it with sysfs
++ *
++ * @name: the name for the kset
++ * @parent: the parent kobject of this kobject, if any.
++ *
++ * This function creates a kobject structure dynamically and registers it
++ * with sysfs.  When you are finished with this structure, call
++ * kobject_put() and the structure will be dynamically freed when
++ * it is no longer being used.
++ *
++ * If the kobject was not able to be created, NULL will be returned.
++ */
++struct kobject *kobject_create_and_add(const char *name, struct kobject 
*parent)
++{
++      struct kobject *kobj;
++      int retval;
++
++      kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
++      if (!kobj)
++              return NULL;
++
++      kobject_init(kobj);
++      kobj->ktype = &dynamic_kobj_ktype;
++      kobj->parent = parent;
++
++      retval = kobject_set_name(kobj, "%s", name);
++      if (retval) {
++              printk(KERN_WARNING "%s: kobject_set_name error: %d\n",
++                      __FUNCTION__, retval);
++              goto err;
++      }
++
++      retval = kobject_add(kobj);
++      if (retval) {
++              printk(KERN_WARNING "%s: kobject_add error: %d\n",
++                      __FUNCTION__, retval);
++              goto err;
++      }
++
++      return kobj;
++
++err:
++      kobject_put(kobj);
++      return NULL;
++}
++
++/**
++ * kobject_init_and_add - initialize a kobject structure and add it to the 
kobject hierarchy
++ * @kobj: pointer to the kobject to initialize
++ * @ktype: pointer to the ktype for this kobject.
++ * @parent: pointer to the parent of this kobject.
++ * @fmt: the name of the kobject.
++ *
++ * This function combines the call to kobject_init() and
++ * kobject_add().  The same type of error handling after a call to
++ * kobject_add() and kobject lifetime rules are the same here.
++ */
++int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
++                         struct kobject *parent, const char *fmt, ...)
++{
++      int retval;
++      int limit;
++      int need;
++      va_list args;
++      char *name;
++
++      /* find out how big a buffer we need */
++      name = kmalloc(1024, GFP_KERNEL);
++      if (!name) {
++              retval = -ENOMEM;
++              goto out;
++      }
++      va_start(args, fmt);
++      need = vsnprintf(name, 1024, fmt, args);
++      va_end(args);
++      kfree(name);
++
++      /* Allocate the new space and copy the string in */
++      limit = need + 1;
++      name = kmalloc(limit, GFP_KERNEL);
++      if (!name) {
++              retval = -ENOMEM;
++              goto out;
++      }
++
++      va_start(args, fmt);
++      need = vsnprintf(name, limit, fmt, args);
++      va_end(args);
++
++      kobject_init(kobj);
++
++      kobj->ktype = ktype;
++      kobj->parent = parent;
++
++      retval = kobject_set_name(kobj, name);
++      kfree(name);
++      if (retval)
++              goto out;
++
++      retval = kobject_add(kobj);
++      if (retval)
++              goto out;
++
++out:
++      return retval;
++}
++
+diff -Nurp ofa_kernel-1.4-orig/drivers/infiniband/core/Makefile 
ofa_kernel-1.4/drivers/infiniband/core/Makefile
+--- ofa_kernel-1.4-orig/drivers/infiniband/core/Makefile       2008-07-07 
15:06:10.000000000 +0200
++++ ofa_kernel-1.4/drivers/infiniband/core/Makefile    2008-07-11 
20:01:44.000000000 +0200
+@@ -8,7 +8,7 @@ obj-$(CONFIG_INFINIBAND_USER_ACCESS) +=        
+                                       $(user_access-y)
+ 
+ ib_core-y :=                  packer.o ud_header.o verbs.o sysfs.o \
+-                              device.o fmr_pool.o cache.o
++                              device.o fmr_pool.o cache.o kobject_backport.o
+ ib_core-$(CONFIG_INFINIBAND_USER_MEM) += umem.o
+ 
+ ib_mad-y :=                   mad.o smi.o agent.o mad_rmpp.o
-- 
1.5.5



_______________________________________________
ewg mailing list
ewg@lists.openfabrics.org
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/ewg

Reply via email to