Linux MIPS Architecture development
 help / color / mirror / Atom feed
From: Ralf Baechle <ralf@linux-mips.org>
To: durai <durai@isofttech.com>
Cc: linux-mips@linux-mips.org
Subject: Re: file handling in kernel mode
Date: Sun, 16 Nov 2003 23:51:33 +0100	[thread overview]
Message-ID: <20031116225133.GA7808@linux-mips.org> (raw)
In-Reply-To: <007801c3ac20$070adff0$0205a8c0@DURAI>

On Sun, Nov 16, 2003 at 02:30:05PM +0530, durai wrote:

> Hello,
> I need to read a file from a device driver and i wrote a sample driver
> like this
> 
> This kernel mode code which try to read the file until end of file is
> reached. This code had been is working without any problems in RedHat
> linux and uClinux.
> But the same code causes a General Protection Fault in my mips linux.
> I tested the same code in mips running on uClinux which runs well.
> what is wrong with mips linux?

If the screen says general protection fault it's wasn't a MIPS box :-)

> #define __KERNEL_SYSCALLS__
> 
> #include <linux/version.h>
> #ifdef MODULE
> #ifdef MODVERSIONS
> #include <linux/modversions.h>
> #endif
> #include <linux/module.h>
> #else
> #define MOD_INC_USE_COUNT
> #define MOD_DEC_USE_COUNT
> #endif

Ouch.  You can replace that all with a single line:

#include <linux/module.h>

> int init_module(void)

[...]

> void cleanup_module(void)

[...]

The use of init_module and cleanup_module is deprecated, use something
like this instead:

#include <linux/init.h>

static int __init foo_init_module(void)
{
	return 0;
}

static void __exit foo_cleanup_module(void)
{
}

module_init(foo_init_module);
module_exit(foo_cleanup_module);


> int test_open(void )
> {
>     int ifp,bcount;
>     mm_segment_t fs;
>     char buffer[0x1000];
                  ^^^^^^

And this is the BIG no-no.  Never allocate large amounts of data on the
kernel stack which is only 8k which are used for various other stuff
also..

> 
>     // for file opening temporarily tell the kernel I am not a user for
>     // memory management segment access
>     fs = get_fs();
>     set_fs(KERNEL_DS);
>     // open the file with the firmware for uploading
>     if (ifp = open( "/etc/hotplug/isl3890.arm", O_RDONLY, 0 ), ifp < 0)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^

Hard coding file names is generally considered bad design; this topic has
been discussed to death numerous times on linux-kernel.  The general
recommendation is to use a special such as /dev/foodevice; the firmware
would then simply be loader by cat bar > //dev/foodevice or similar.

For 2.4.23 (I'm going to merge with 2.4.23-rc1 tonight) and 2.6 the
recommendation is to use CONFIG_FW_LOADER, the new standard interface
for loading firmware.

  Ralf

  parent reply	other threads:[~2003-11-16 22:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-14 17:42 question regarding put data in the specified section Teresa Tao
2003-11-14 17:42 ` Teresa Tao
2003-11-15 12:53 ` Ralf Baechle
2003-11-16  9:00   ` file handling in kernel mode durai
2003-11-16  9:00     ` durai
2003-11-16 22:51     ` Ralf Baechle [this message]
2003-11-17  0:46       ` Brad Parker
2003-11-17  1:06         ` Ralf Baechle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20031116225133.GA7808@linux-mips.org \
    --to=ralf@linux-mips.org \
    --cc=durai@isofttech.com \
    --cc=linux-mips@linux-mips.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox