From: Petr Vandrovec <vandrove@vc.cvut.cz>
To: linux-kernel@vger.kernel.org
Cc: schlicht@uni-mannheim.de, alan@lxorguk.ukuu.org.uk
Subject: [PATCH] Re: patch for errno-issue (with soundcore)
Date: Mon, 13 Jan 2003 20:10:07 +0100 [thread overview]
Message-ID: <20030113191007.GA2814@vana> (raw)
In-Reply-To: <200301131810.53089.schlicht@uni-mannheim.de>
>
> Now, at least, I understood the real problem...
> 'errno' is only needed because open(), close(), llseek() and read() are used,
> which do a syscall and the return code is written to a variable called
> 'errno'. This is NOT the 'errno' variable defined in lib/errno.c... OK.
>
> And so the real problem is using these functions and as we ARE in the kernel
> mode we do not really need the kernel traps...
Hi,
can someone with sound card requiring firmware download (OSS's trix,
sb_common, msnd_pinnacle, sscape, maui or pss) verify that code below
works? I know that it compiles without warnings, and looks obviously
correct (to me), but...
I think that I do not need any locking around reading i_size, as
nothing bad should happen if size changes, you'll get damaged firmware
upload at worst, and if you are updating firmware file while kernel
reads it, you deserve it (besides that vfs_read is one who will do final
check). And sys_stat (getattr) does not take any lock too, unless I
missed something.
Patch is for 2.5.57.
BTW, should I convert it to goto? It was really annoying that I had to
fix 3 error paths instead of one ;-)
Best regards,
Petr Vandrovec
vandrove@vc.cvut.cz
diff -urdN linux/sound/sound_firmware.c linux/sound/sound_firmware.c
--- linux/sound/sound_firmware.c 2003-01-13 18:24:36.000000000 +0000
+++ linux/sound/sound_firmware.c 2003-01-13 18:45:12.000000000 +0000
@@ -9,39 +9,40 @@
static int do_mod_firmware_load(const char *fn, char **fp)
{
- int fd;
+ struct file* filp;
long l;
char *dp;
+ loff_t pos;
- fd = open(fn, 0, 0);
- if (fd == -1)
+ filp = filp_open(fn, 0, 0);
+ if (IS_ERR(filp))
{
printk(KERN_INFO "Unable to load '%s'.\n", fn);
return 0;
}
- l = lseek(fd, 0L, 2);
+ l = filp->f_dentry->d_inode->i_size;
if (l <= 0 || l > 131072)
{
printk(KERN_INFO "Invalid firmware '%s'\n", fn);
- sys_close(fd);
+ filp_close(filp, current->files);
return 0;
}
- lseek(fd, 0L, 0);
dp = vmalloc(l);
if (dp == NULL)
{
printk(KERN_INFO "Out of memory loading '%s'.\n", fn);
- sys_close(fd);
+ filp_close(filp, current->files);
return 0;
}
- if (read(fd, dp, l) != l)
+ pos = 0;
+ if (vfs_read(filp, dp, l, &pos) != l)
{
printk(KERN_INFO "Failed to read '%s'.\n", fn);
vfree(dp);
- sys_close(fd);
+ filp_close(filp, current->files);
return 0;
}
- close(fd);
+ filp_close(filp, current->files);
*fp = dp;
return (int) l;
}
prev parent reply other threads:[~2003-01-13 19:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-13 16:33 patch for errno-issue (with soundcore) Petr Vandrovec
2003-01-13 17:10 ` Thomas Schlichter
2003-01-13 19:10 ` Petr Vandrovec [this message]
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=20030113191007.GA2814@vana \
--to=vandrove@vc.cvut.cz \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=schlicht@uni-mannheim.de \
/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