All of lore.kernel.org
 help / color / mirror / Atom feed
* Good Idea (tm): Code Consolidation for Functions and Macros that Access the Process Address Space
@ 2002-10-06  0:58 Joseph D. Wagner
  2002-10-06  9:50 ` Russell King
  0 siblings, 1 reply; 4+ messages in thread
From: Joseph D. Wagner @ 2002-10-06  0:58 UTC (permalink / raw)
  To: Linux Kernel Development List

SUBJECT: Good Idea (tm): Code Consolidation for Functions and Macros
that Access the Process Address Space

PROBLEM: Eight (8) functions/macros are near duplicates of, and
equivalent to, other functions/macros that access the process address
space.  Specifically:

	get_user		duplicates get_user_ret
	__get_user		duplicates __get_user_ret
	put_user		duplicates put_user_ret
	__put_user		duplicates __put_user_ret
	copy_from_user	duplicates copy_from_user_ret
	__copy_from_user	duplicates copy_from_user_ret
	copy_to_user	duplicates copy_to_user_ret
	__copy_to_user	duplicates copy_to_user_ret

EXPLAINATION: One functional difference exists between the
functions/macros with "_ret" and those without: functions/macros with
"_ret" return an error code; those without "_ret" return void.

Since the only difference is whether or not an error code is returned,
the functions/macros can be used interchangeably.

Remember, if a function call has no place for a returned value to go,
nothing bad happens; the returned value is simply ignored/discarded.

WHY THIS SHOULD BE CHANGED:
1) Easier to maintain code (because there's less of it to maintain).
2) Less code means smaller kernel.
3) Forces better coding structures and procedures (because no matter
which function the user will choose under the new system, an error code
will always be returned).
4) Is backward compatible with all existing code.
5) The solution can be seamlessly integrated.
6) The overhead for returning an error code is nominal.

SOLUTION:

Use the #define Preprocessor Directive for Symbolic Constants.  Here's
some sample code:

	#define get_user get_user_ret
	#define __get_user __get_user_ret
	#define put_user put_user_ret
	#define __put_user __put_user_ret
	#define copy_from_user copy_from_user_ret
	#define __copy_from_user copy_from_user_ret
	#define copy_to_user copy_to_user_ret
	#define __copy_to_user copy_to_user_ret

By placing that code in the appropriate header file(s), the #define
statements will trickle down to the appropriate source files.

Hence the functions/macros without "_ret" can be eliminated, resulting
in code consolidation.

NOTE: The validity of using a #define Preprocessor Directive as a
Symbolic Constant on a function has been tested, and proven viable, in
the following sample program:

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

void Hello();
void Hello_Again();

#define Hi Hello
#define Hi_Again Hello_Again

/*
void Hi();
void Hi_Again();
*/

int main() {
	Hello();
	Hello_Again();
	Hi();
	Hi_Again();
}

void Hello () {
	cout << "Hello." << endl;
}

void Hello_Again() {
	cout << "Hello, again." << endl;
}

/*
void Hi() {
	cout << "Hi." << endl;
}

void Hi_Again() {
	cout << "Hi, again." << endl;
}
*/



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-10-06 13:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-10-06  0:58 Good Idea (tm): Code Consolidation for Functions and Macros that Access the Process Address Space Joseph D. Wagner
2002-10-06  9:50 ` Russell King
2002-10-06 12:40   ` Joseph D. Wagner
2002-10-06 13:29     ` Russell King

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.