[SPARC]: Use kthread infrastructure in envctrl

2005-08-09 Thread Linux Kernel Mailing List
tree e734f30f6123ae2b4e3ba545e9017d6d0498b3e7
parent 00dd1e433967872f3997a45d5adf35056fdf2f56
author Christoph Hellwig [EMAIL PROTECTED] Wed, 10 Aug 2005 02:30:07 -0700
committer David S. Miller [EMAIL PROTECTED] Wed, 10 Aug 2005 02:30:07 -0700

[SPARC]: Use kthread infrastructure in envctrl

envctrl currently uses very odd ways to stop a thread, using various
things that should be exposed to drivers at all.

This patch (which is untested as I don't have sparc hardware) switches
it to use the proper kthread infrastructure.

Signed-off-by: Christoph Hellwig [EMAIL PROTECTED]
Signed-off-by: David S. Miller [EMAIL PROTECTED]

 drivers/sbus/char/envctrl.c |   41 ++---
 1 files changed, 10 insertions(+), 31 deletions(-)

diff --git a/drivers/sbus/char/envctrl.c b/drivers/sbus/char/envctrl.c
--- a/drivers/sbus/char/envctrl.c
+++ b/drivers/sbus/char/envctrl.c
@@ -24,6 +24,7 @@
 #include linux/config.h
 #include linux/module.h
 #include linux/sched.h
+#include linux/kthread.h
 #include linux/errno.h
 #include linux/delay.h
 #include linux/ioport.h
@@ -1010,16 +1011,13 @@ static int kenvctrld(void *__unused)
 
poll_interval = 5000; /* TODO env_mon_interval */
 
-   daemonize(kenvctrld);
-   allow_signal(SIGKILL);
-
-   kenvctrld_task = current;
-
printk(KERN_INFO envctrl: %s starting...\n, current-comm);
for (;;) {
-   if(msleep_interruptible(poll_interval))
-   break;
+   msleep_interruptible(poll_interval);
 
+   if (kthread_should_stop())
+   break;
+   
for (whichcpu = 0; whichcpu  ENVCTRL_MAX_CPU; ++whichcpu) {
if (0  envctrl_read_cpu_info(whichcpu, cputemp,
  ENVCTRL_CPUTEMP_MON,
@@ -1118,9 +1116,11 @@ done:
i2c_childlist[i].addr, (0 == i) ? (\n) : ( ));
}
 
-   err = kernel_thread(kenvctrld, NULL, CLONE_FS | CLONE_FILES);
-   if (err  0)
+   kenvctrld_task = kthread_run(kenvctrld, NULL, kenvctrld);
+   if (IS_ERR(kenvctrld_task)) {
+   err = ERR_PTR(kenvctrld_task);
goto out_deregister;
+   }
 
return 0;
 
@@ -1142,28 +1142,7 @@ static void __exit envctrl_cleanup(void)
 {
int i;
 
-   if (NULL != kenvctrld_task) {
-   force_sig(SIGKILL, kenvctrld_task);
-   for (;;) {
-   struct task_struct *p;
-   int found = 0;
-
-   read_lock(tasklist_lock);
-   for_each_process(p) {
-   if (p == kenvctrld_task) {
-   found = 1;
-   break;
-   }
-   }
-   read_unlock(tasklist_lock);
-
-   if (!found)
-   break;
-
-   msleep(1000);
-   }
-   kenvctrld_task = NULL;
-   }
+   kthread_stop(kenvctrld_task);
 
iounmap(i2c);
misc_deregister(envctrl_dev);
-
To unsubscribe from this list: send the line unsubscribe git-commits-head in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[SPARC]: Use kthread infrastructure in bbc_envctrl

2005-08-09 Thread Linux Kernel Mailing List
tree e7e9f356f14b5353f8b07273948beb1eef0ec8f9
parent 218b29e0c3995ee15782de55ad1dd74cce1a728d
author Christoph Hellwig [EMAIL PROTECTED] Wed, 10 Aug 2005 03:32:25 -0700
committer David S. Miller [EMAIL PROTECTED] Wed, 10 Aug 2005 03:32:25 -0700

[SPARC]: Use kthread infrastructure in bbc_envctrl

Signed-off-by: Christoph Hellwig [EMAIL PROTECTED]
Signed-off-by: David S. Miller [EMAIL PROTECTED]

 drivers/sbus/char/bbc_envctrl.c |   39 ++-
 1 files changed, 10 insertions(+), 29 deletions(-)

diff --git a/drivers/sbus/char/bbc_envctrl.c b/drivers/sbus/char/bbc_envctrl.c
--- a/drivers/sbus/char/bbc_envctrl.c
+++ b/drivers/sbus/char/bbc_envctrl.c
@@ -7,6 +7,7 @@
 #define __KERNEL_SYSCALLS__
 
 #include linux/kernel.h
+#include linux/kthread.h
 #include linux/sched.h
 #include linux/slab.h
 #include linux/delay.h
@@ -459,10 +460,6 @@ static struct task_struct *kenvctrld_tas
 
 static int kenvctrld(void *__unused)
 {
-   daemonize(kenvctrld);
-   allow_signal(SIGKILL);
-   kenvctrld_task = current;
-
printk(KERN_INFO bbc_envctrl: kenvctrld starting...\n);
last_warning_jiffies = jiffies - WARN_INTERVAL;
for (;;) {
@@ -470,7 +467,7 @@ static int kenvctrld(void *__unused)
struct bbc_fan_control *fp;
 
msleep_interruptible(POLL_INTERVAL);
-   if (signal_pending(current))
+   if (kthread_should_stop())
break;
 
for (tp = all_bbc_temps; tp; tp = tp-next) {
@@ -577,7 +574,6 @@ int bbc_envctrl_init(void)
int temp_index = 0;
int fan_index = 0;
int devidx = 0;
-   int err = 0;
 
while ((echild = bbc_i2c_getdev(devidx++)) != NULL) {
if (!strcmp(echild-prom_name, temperature))
@@ -585,9 +581,13 @@ int bbc_envctrl_init(void)
if (!strcmp(echild-prom_name, fan-control))
attach_one_fan(echild, fan_index++);
}
-   if (temp_index != 0  fan_index != 0)
-   err = kernel_thread(kenvctrld, NULL, CLONE_FS | CLONE_FILES);
-   return err;
+   if (temp_index != 0  fan_index != 0) {
+   kenvctrld_task = kthread_run(kenvctrld, NULL, kenvctrld);
+   if (IS_ERR(kenvctrld_task))
+   return PTR_ERR(kenvctrld_task);
+   }
+
+   return 0;
 }
 
 static void destroy_one_temp(struct bbc_cpu_temperature *tp)
@@ -607,26 +607,7 @@ void bbc_envctrl_cleanup(void)
struct bbc_cpu_temperature *tp;
struct bbc_fan_control *fp;
 
-   if (kenvctrld_task != NULL) {
-   force_sig(SIGKILL, kenvctrld_task);
-   for (;;) {
-   struct task_struct *p;
-   int found = 0;
-
-   read_lock(tasklist_lock);
-   for_each_process(p) {
-   if (p == kenvctrld_task) {
-   found = 1;
-   break;
-   }
-   }
-   read_unlock(tasklist_lock);
-   if (!found)
-   break;
-   msleep(1000);
-   }
-   kenvctrld_task = NULL;
-   }
+   kthread_stop(kenvctrld_task);
 
tp = all_bbc_temps;
while (tp != NULL) {
-
To unsubscribe from this list: send the line unsubscribe git-commits-head in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[SUNRPC]: Fix nsec -- usec conversion.

2005-08-09 Thread Linux Kernel Mailing List
tree 4db1741d4400b704609d495c68728c962ea3982a
parent 00dd1e433967872f3997a45d5adf35056fdf2f56
author David S. Miller [EMAIL PROTECTED] Wed, 10 Aug 2005 04:57:12 -0700
committer David S. Miller [EMAIL PROTECTED] Wed, 10 Aug 2005 04:57:12 -0700

[SUNRPC]: Fix nsec -- usec conversion.

We need to divide, not multiply.  While we're here,
use NSEC_PER_USEC instead of a magic constant.

Based upon a report from Josip Loncaric and a patch
by Andrew Morton.

Signed-off-by: David S. Miller [EMAIL PROTECTED]

 net/sunrpc/svcsock.c |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -586,7 +586,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
}
if (skb-stamp.tv_sec == 0) {
skb-stamp.tv_sec = xtime.tv_sec; 
-   skb-stamp.tv_usec = xtime.tv_nsec * 1000; 
+   skb-stamp.tv_usec = xtime.tv_nsec / NSEC_PER_USEC; 
/* Don't enable netstamp, sunrpc doesn't 
   need that much accuracy */
}
-
To unsubscribe from this list: send the line unsubscribe git-commits-head in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] I2O: added pci_request_regions() before using the controller

2005-08-09 Thread Linux Kernel Mailing List
tree cc0a26be95e1a93e675bbe40dd7528db7ed2baa1
parent a7df26da158ad64d56cc32934aa38a07d03a6fc9
author Markus Lidel [EMAIL PROTECTED] Wed, 10 Aug 2005 04:30:57 -0700
committer Linus Torvalds [EMAIL PROTECTED] Wed, 10 Aug 2005 07:59:52 -0700

[PATCH] I2O: added pci_request_regions() before using the controller

Added pci_request_regions() before using the controller to avoid duplicate
usage of the I2O controller when the dpt_i2o driver and I2O subsystem is
loaded at the same time.

Signed-off-by: Markus Lidel [EMAIL PROTECTED]
Cc: James Bottomley [EMAIL PROTECTED]
Signed-off-by: Andrew Morton [EMAIL PROTECTED]
Signed-off-by: Linus Torvalds [EMAIL PROTECTED]

 drivers/message/i2o/pci.c |   10 ++
 1 files changed, 10 insertions(+)

diff --git a/drivers/message/i2o/pci.c b/drivers/message/i2o/pci.c
--- a/drivers/message/i2o/pci.c
+++ b/drivers/message/i2o/pci.c
@@ -32,6 +32,8 @@
 #include linux/i2o.h
 #include core.h
 
+#define OSM_DESCRIPTIONI2O-subsystem
+
 /* PCI device id table for all I2O controllers */
 static struct pci_device_id __devinitdata i2o_pci_ids[] = {
{PCI_DEVICE_CLASS(PCI_CLASS_INTELLIGENT_I2O  8, 0x00)},
@@ -66,6 +68,8 @@ static void i2o_pci_free(struct i2o_cont
 
if (c-base.virt)
iounmap(c-base.virt);
+
+   pci_release_regions(c-pdev);
 }
 
 /**
@@ -84,6 +88,11 @@ static int __devinit i2o_pci_alloc(struc
struct device *dev = pdev-dev;
int i;
 
+   if (pci_request_regions(pdev, OSM_DESCRIPTION)) {
+   printk(KERN_ERR %s: device already claimed\n, c-name);
+   return -ENODEV;
+   }
+
for (i = 0; i  6; i++) {
/* Skip I/O spaces */
if (!(pci_resource_flags(pdev, i)  IORESOURCE_IO)) {
@@ -138,6 +147,7 @@ static int __devinit i2o_pci_alloc(struc
c-base.virt = ioremap_nocache(c-base.phys, c-base.len);
if (!c-base.virt) {
printk(KERN_ERR %s: Unable to map controller.\n, c-name);
+   i2o_pci_free(c);
return -ENOMEM;
}
 
-
To unsubscribe from this list: send the line unsubscribe git-commits-head in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[NET]: Fix memory leak in sys_{send,recv}msg() w/compat

2005-08-09 Thread Linux Kernel Mailing List
tree b49a930e65ed4f30b4f8f2aac4ddb08c41bc4b79
parent 3501466941347f0e1992b2672affb3feb92925fd
author Andrew Morton [EMAIL PROTECTED] Wed, 10 Aug 2005 05:29:19 -0700
committer David S. Miller [EMAIL PROTECTED] Wed, 10 Aug 2005 05:29:19 -0700

[NET]: Fix memory leak in sys_{send,recv}msg() w/compat

From: Dave Johnson [EMAIL PROTECTED]

sendmsg()/recvmsg() syscalls from o32/n32 apps to a 64bit kernel will
cause a kernel memory leak if iov_len  UIO_FASTIOV for each syscall!

This is because both sys_sendmsg() and verify_compat_iovec() kmalloc a
new iovec structure.  Only the one from sys_sendmsg() is free'ed.

I wrote a simple test program to confirm this after identifying the
problem:

http://davej.org/programs/testsendmsg.c

Note that the below fix will break solaris_sendmsg()/solaris_recvmsg() as
it also calls verify_compat_iovec() but expects it to malloc internally.

[ I fixed that. -DaveM ]

Signed-off-by: Andrew Morton [EMAIL PROTECTED]
Signed-off-by: David S. Miller [EMAIL PROTECTED]

 arch/sparc64/solaris/socket.c |  191 +-
 net/compat.c  |9 -
 2 files changed, 118 insertions(+), 82 deletions(-)

diff --git a/arch/sparc64/solaris/socket.c b/arch/sparc64/solaris/socket.c
--- a/arch/sparc64/solaris/socket.c
+++ b/arch/sparc64/solaris/socket.c
@@ -16,6 +16,7 @@
 #include linux/net.h
 #include linux/compat.h
 #include net/compat.h
+#include net/sock.h
 
 #include asm/uaccess.h
 #include asm/string.h
@@ -297,121 +298,165 @@ asmlinkage int solaris_sendmsg(int fd, s
 {
struct socket *sock;
char address[MAX_SOCK_ADDR];
-   struct iovec iov[UIO_FASTIOV];
+   struct iovec iovstack[UIO_FASTIOV], *iov = iovstack;
unsigned char ctl[sizeof(struct cmsghdr) + 20];
unsigned char *ctl_buf = ctl;
-   struct msghdr kern_msg;
-   int err, total_len;
+   struct msghdr msg_sys;
+   int err, ctl_len, iov_size, total_len;
 
-   if(msghdr_from_user32_to_kern(kern_msg, user_msg))
-   return -EFAULT;
-   if(kern_msg.msg_iovlen  UIO_MAXIOV)
-   return -EINVAL;
-   err = verify_compat_iovec(kern_msg, iov, address, VERIFY_READ);
-   if (err  0)
+   err = -EFAULT;
+   if (msghdr_from_user32_to_kern(msg_sys, user_msg))
+   goto out;
+
+   sock = sockfd_lookup(fd, err);
+   if (!sock)
goto out;
+
+   /* do not move before msg_sys is valid */
+   err = -EMSGSIZE;
+   if (msg_sys.msg_iovlen  UIO_MAXIOV)
+   goto out_put;
+
+   /* Check whether to allocate the iovec area*/
+   err = -ENOMEM;
+   iov_size = msg_sys.msg_iovlen * sizeof(struct iovec);
+   if (msg_sys.msg_iovlen  UIO_FASTIOV) {
+   iov = sock_kmalloc(sock-sk, iov_size, GFP_KERNEL);
+   if (!iov)
+   goto out_put;
+   }
+
+   err = verify_compat_iovec(msg_sys, iov, address, VERIFY_READ);
+   if (err  0)
+   goto out_freeiov;
total_len = err;
 
-   if(kern_msg.msg_controllen) {
-   struct sol_cmsghdr __user *ucmsg = kern_msg.msg_control;
+   err = -ENOBUFS;
+   if (msg_sys.msg_controllen  INT_MAX)
+   goto out_freeiov;
+
+   ctl_len = msg_sys.msg_controllen;
+   if (ctl_len) {
+   struct sol_cmsghdr __user *ucmsg = msg_sys.msg_control;
unsigned long *kcmsg;
compat_size_t cmlen;
 
-   if (kern_msg.msg_controllen = sizeof(compat_size_t))
-   return -EINVAL;
+   err = -EINVAL;
+   if (ctl_len = sizeof(compat_size_t))
+   goto out_freeiov;
 
-   if(kern_msg.msg_controllen  sizeof(ctl)) {
+   if (ctl_len  sizeof(ctl)) {
err = -ENOBUFS;
-   ctl_buf = kmalloc(kern_msg.msg_controllen, GFP_KERNEL);
-   if(!ctl_buf)
+   ctl_buf = kmalloc(ctl_len, GFP_KERNEL);
+   if (!ctl_buf)
goto out_freeiov;
}
__get_user(cmlen, ucmsg-cmsg_len);
kcmsg = (unsigned long *) ctl_buf;
*kcmsg++ = (unsigned long)cmlen;
err = -EFAULT;
-   if(copy_from_user(kcmsg, ucmsg-cmsg_level,
- kern_msg.msg_controllen - 
sizeof(compat_size_t)))
+   if (copy_from_user(kcmsg, ucmsg-cmsg_level,
+  ctl_len - sizeof(compat_size_t)))
goto out_freectl;
-   kern_msg.msg_control = ctl_buf;
+   msg_sys.msg_control = ctl_buf;
}
-   kern_msg.msg_flags = solaris_to_linux_msgflags(user_flags);
+   msg_sys.msg_flags = solaris_to_linux_msgflags(user_flags);
 
-   lock_kernel();
-   sock = sockfd_lookup(fd, err);
-   if (sock != NULL) {
-   if