Get pointer for existing device class (struct class) in Linux kernel module


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Get pointer for existing device class (struct class) in Linux kernel module
# 1  
Old 04-20-2013
Get pointer for existing device class (struct class) in Linux kernel module

Hi all!

I am trying to register a device in an existing device class, but I am

having trouble getting the pointer to an existing class.
I can create a class in a module, get the pointer to it and then use

it to register the device with:

Code:
*cl = class_create(THIS_MODULE, className);
dev_ret = device_create(*cl, NULL, *dev, NULL, driverName);

However I need to register another device in the same class with

another module, but I couldn't find a way to get the pointer to an

existing class. And I can not crete the class again in the other

module, because since class already exists class_create() returns NULL

and not the pointer to the class required by device_create().

I found in a function that returns a pointer to a class by its name googling (sorry system did not allowed to post url)

Code:
struct class * class_find(char * name)

However when I try to compile the function compiler says it does not exist.
I thougth this function was exported by the kernel (my module have
license GPL) but it appears it is not.
Maybe I need to include some header?

I know its a patch I suposed it was in main stream kernel already.
I tried to rewrite this function since the code is available. The code is:

Code:
+struct class * class_find(char * name)
+{
+	struct class * this_class;
+
+	if (!name)
+		return NULL;
+
+	list_for_each_entry(this_class, &class_subsys.kset.list, subsys.kset.kobj.entry) {
+		if (!(strcmp(this_class->name, name)))
+			return this_class;
+	}
+
+	return NULL;
+}

But when I try to iterate over class_subsys with:

list_for_each_entry(this_class, &class_subsys.kset.list, subsys.kset.kobj.entry)

now symbol class_subsys is not found. Again I thougth it is exported

to the kernel.

I am not sure what is missing. Some header?
Am I doing it the wrong way?
There is another function to do it?

I supose if I could traverse sysfs from start I could get a pointer to an existing class.
But I also did not find how to start traversing sysfs.
All functions I have seen requires a pointer to kobject or kset to

start traversing. But I have no poniter even to the root of sysfs or kernel objects, so I can not start traversin the tree to get a class pointer.

Can anyone point me in the right direction please?

Last edited by jim mcnamara; 04-20-2013 at 05:08 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

C++ : Base class member function not accessible from derived class

Hello All, I am a learner in C++. I was testing my inheritance knowledge with following piece of code. #include <iostream> using namespace std; class base { public : void display() { cout << "In base display()" << endl; } void display(int k) {... (2 Replies)
Discussion started by: anand.shah
2 Replies

2. Programming

Size of Derived class, upon virtual base class inheritance

I have the two class definition as follows. class A { public: int a; }; class B : virtual public A{ }; The size of class A is shown as 4, and size of class B is shown as 16. Why is this effect ?. (2 Replies)
Discussion started by: techmonk
2 Replies

3. Programming

static use for class inside the same class c++

Hi, I believe the next code is wrong: class Egg { Egg e; int i; Egg(int ii=0) : i(ii) {} }; because you would end up with an endless definition (memory allocation) of Egg objects, thus int i. Ok, so God Eckel proposes for a singleton: class Egg { static Egg e; int... (5 Replies)
Discussion started by: xavipoes
5 Replies

4. Fedora

Is Kernel module is the same as a device driver?

I have been reading prep questions for my second unix academy exam, and there's a nuance, I'm not sure I understand it correctly. I've been under impression from my readings of book by Evi Nemeth and from unix academy DVDs I've been watching, that kernel's modules are drivers. I think of it, as... (25 Replies)
Discussion started by: newlinuxuser1
25 Replies

5. Programming

Class Pointer initialization C++

Hello everyone, I have a question, that are the following ways of pointer intialization same ? ClassA *point; point = 0; point = new ClassA; Thanks a load in advance!! Regards, (10 Replies)
Discussion started by: mind@work
10 Replies

6. Programming

Pointer for class not working that well. Syntax I think.

I'll be gratefull for any help. Thanks. :) This is the non class type error: # g++ -I/usr/include/mysql -I/usr/include/mysql++ -lmysqlpp -L/usr/lib/mysql -L/usr/local/lib/mysql++ loaddsgsports.cpp -o loaddsgsports loaddsgsports.cpp: In function âint outputToImport(const char*, const char*,... (1 Reply)
Discussion started by: sepoto
1 Replies

7. Programming

C++ class definition with a member of the same class

Hi, i have a question about C++. Is it possible to declare a class with a member ot the same class? For example, a linked list or i want to convert this C code to C++ class (Elemento) typedef struct elemento { char name; char value; List<struct elemento> ltElementos; ... (7 Replies)
Discussion started by: pogdorica
7 Replies

8. UNIX for Dummies Questions & Answers

car class (not school class)

im just trying to have some fun and kill some time writing a c++ program that has a person type in a car make and model then gives them a year and a price. or something like that. i always have problems getting it goin but once the ball is rolling im usually pretty good. anyone wanna help me out? ... (1 Reply)
Discussion started by: rickym2626
1 Replies

9. UNIX for Advanced & Expert Users

Passing socket struct between kernel threads - module programming

I write kernel module with kernel threads using linux/kthread.h on 2.6.* kernel I tried to passing data between two kernel threads with data argument of kthread_run( fun, data , NAME ); but this is not work I dont know why. I tried many possibility and nothing works. So I thought that... (0 Replies)
Discussion started by: marcintom
0 Replies

10. Shell Programming and Scripting

can't get perl Class::Struct to work

This is my code: #!/usr/bin/perl -w use strict; use Class::Struct; struct App => { name => '$', }; sub App::name { my $self = shift; if( @_ ) { $self->{'name'} = shift; } return $self->{'name'}; (3 Replies)
Discussion started by: IMTheNachoMan
3 Replies
Login or Register to Ask a Question