2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* ipmi_devintf.c
|
|
|
|
*
|
|
|
|
* Linux device interface for the IPMI message handler.
|
|
|
|
*
|
|
|
|
* Author: MontaVista Software, Inc.
|
|
|
|
* Corey Minyard <minyard@mvista.com>
|
|
|
|
* source@mvista.com
|
|
|
|
*
|
|
|
|
* Copyright 2002 MontaVista Software Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
|
|
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
|
|
|
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/poll.h>
|
2009-10-04 20:11:37 +08:00
|
|
|
#include <linux/sched.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/ipmi.h>
|
2006-03-31 18:30:41 +08:00
|
|
|
#include <linux/mutex.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/init.h>
|
2005-05-20 14:56:23 +08:00
|
|
|
#include <linux/device.h>
|
2005-06-24 13:01:45 +08:00
|
|
|
#include <linux/compat.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
struct ipmi_file_private
|
|
|
|
{
|
|
|
|
ipmi_user_t user;
|
|
|
|
spinlock_t recv_msg_lock;
|
|
|
|
struct list_head recv_msgs;
|
|
|
|
struct file *file;
|
|
|
|
struct fasync_struct *fasync_queue;
|
|
|
|
wait_queue_head_t wait;
|
2006-03-31 18:30:41 +08:00
|
|
|
struct mutex recv_mutex;
|
2005-04-17 06:20:36 +08:00
|
|
|
int default_retries;
|
|
|
|
unsigned int default_retry_time_ms;
|
|
|
|
};
|
|
|
|
|
2010-06-02 20:28:52 +08:00
|
|
|
static DEFINE_MUTEX(ipmi_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
static void file_receive_handler(struct ipmi_recv_msg *msg,
|
|
|
|
void *handler_data)
|
|
|
|
{
|
|
|
|
struct ipmi_file_private *priv = handler_data;
|
|
|
|
int was_empty;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&(priv->recv_msg_lock), flags);
|
|
|
|
|
|
|
|
was_empty = list_empty(&(priv->recv_msgs));
|
|
|
|
list_add_tail(&(msg->link), &(priv->recv_msgs));
|
|
|
|
|
|
|
|
if (was_empty) {
|
|
|
|
wake_up_interruptible(&priv->wait);
|
|
|
|
kill_fasync(&priv->fasync_queue, SIGIO, POLL_IN);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&(priv->recv_msg_lock), flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int ipmi_poll(struct file *file, poll_table *wait)
|
|
|
|
{
|
|
|
|
struct ipmi_file_private *priv = file->private_data;
|
|
|
|
unsigned int mask = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
poll_wait(file, &priv->wait, wait);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->recv_msg_lock, flags);
|
|
|
|
|
2006-03-26 17:37:21 +08:00
|
|
|
if (!list_empty(&(priv->recv_msgs)))
|
2005-04-17 06:20:36 +08:00
|
|
|
mask |= (POLLIN | POLLRDNORM);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&priv->recv_msg_lock, flags);
|
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ipmi_fasync(int fd, struct file *file, int on)
|
|
|
|
{
|
|
|
|
struct ipmi_file_private *priv = file->private_data;
|
|
|
|
int result;
|
|
|
|
|
2010-06-02 20:28:52 +08:00
|
|
|
mutex_lock(&ipmi_mutex); /* could race against open() otherwise */
|
2005-04-17 06:20:36 +08:00
|
|
|
result = fasync_helper(fd, file, on, &priv->fasync_queue);
|
2010-06-02 20:28:52 +08:00
|
|
|
mutex_unlock(&ipmi_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2017-01-06 00:52:10 +08:00
|
|
|
static const struct ipmi_user_hndl ipmi_hndlrs =
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
.ipmi_recv_hndl = file_receive_handler,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int ipmi_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
int if_num = iminor(inode);
|
|
|
|
int rv;
|
|
|
|
struct ipmi_file_private *priv;
|
|
|
|
|
|
|
|
|
|
|
|
priv = kmalloc(sizeof(*priv), GFP_KERNEL);
|
|
|
|
if (!priv)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-06-02 20:28:52 +08:00
|
|
|
mutex_lock(&ipmi_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
priv->file = file;
|
|
|
|
|
|
|
|
rv = ipmi_create_user(if_num,
|
|
|
|
&ipmi_hndlrs,
|
|
|
|
priv,
|
|
|
|
&(priv->user));
|
|
|
|
if (rv) {
|
|
|
|
kfree(priv);
|
2008-05-16 00:46:49 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
file->private_data = priv;
|
|
|
|
|
|
|
|
spin_lock_init(&(priv->recv_msg_lock));
|
|
|
|
INIT_LIST_HEAD(&(priv->recv_msgs));
|
|
|
|
init_waitqueue_head(&priv->wait);
|
|
|
|
priv->fasync_queue = NULL;
|
2006-03-31 18:30:41 +08:00
|
|
|
mutex_init(&priv->recv_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Use the low-level defaults. */
|
|
|
|
priv->default_retries = -1;
|
|
|
|
priv->default_retry_time_ms = 0;
|
|
|
|
|
2008-05-16 00:46:49 +08:00
|
|
|
out:
|
2010-06-02 20:28:52 +08:00
|
|
|
mutex_unlock(&ipmi_mutex);
|
2008-05-16 00:46:49 +08:00
|
|
|
return rv;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ipmi_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct ipmi_file_private *priv = file->private_data;
|
|
|
|
int rv;
|
2015-01-31 13:17:54 +08:00
|
|
|
struct ipmi_recv_msg *msg, *next;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
rv = ipmi_destroy_user(priv->user);
|
|
|
|
if (rv)
|
|
|
|
return rv;
|
|
|
|
|
2015-01-31 13:17:54 +08:00
|
|
|
list_for_each_entry_safe(msg, next, &priv->recv_msgs, link)
|
|
|
|
ipmi_free_recv_msg(msg);
|
|
|
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(priv);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int handle_send_req(ipmi_user_t user,
|
|
|
|
struct ipmi_req *req,
|
|
|
|
int retries,
|
|
|
|
unsigned int retry_time_ms)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
struct ipmi_addr addr;
|
|
|
|
struct kernel_ipmi_msg msg;
|
|
|
|
|
|
|
|
if (req->addr_len > sizeof(struct ipmi_addr))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (copy_from_user(&addr, req->addr, req->addr_len))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
msg.netfn = req->msg.netfn;
|
|
|
|
msg.cmd = req->msg.cmd;
|
|
|
|
msg.data_len = req->msg.data_len;
|
|
|
|
msg.data = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL);
|
|
|
|
if (!msg.data)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* From here out we cannot return, we must jump to "out" for
|
|
|
|
error exits to free msgdata. */
|
|
|
|
|
|
|
|
rv = ipmi_validate_addr(&addr, req->addr_len);
|
|
|
|
if (rv)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (req->msg.data != NULL) {
|
|
|
|
if (req->msg.data_len > IPMI_MAX_MSG_LENGTH) {
|
|
|
|
rv = -EMSGSIZE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (copy_from_user(msg.data,
|
|
|
|
req->msg.data,
|
|
|
|
req->msg.data_len))
|
|
|
|
{
|
|
|
|
rv = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
msg.data_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = ipmi_request_settime(user,
|
|
|
|
&addr,
|
|
|
|
req->msgid,
|
|
|
|
&msg,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
retries,
|
|
|
|
retry_time_ms);
|
|
|
|
out:
|
|
|
|
kfree(msg.data);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-06-27 04:47:01 +08:00
|
|
|
static int handle_recv(struct ipmi_file_private *priv,
|
|
|
|
bool trunc, struct ipmi_recv *rsp,
|
|
|
|
int (*copyout)(struct ipmi_recv *, void __user *),
|
|
|
|
void __user *to)
|
|
|
|
{
|
|
|
|
int addr_len;
|
|
|
|
struct list_head *entry;
|
|
|
|
struct ipmi_recv_msg *msg;
|
|
|
|
unsigned long flags;
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
/* We claim a mutex because we don't want two
|
|
|
|
users getting something from the queue at a time.
|
|
|
|
Since we have to release the spinlock before we can
|
|
|
|
copy the data to the user, it's possible another
|
|
|
|
user will grab something from the queue, too. Then
|
|
|
|
the messages might get out of order if something
|
|
|
|
fails and the message gets put back onto the
|
|
|
|
queue. This mutex prevents that problem. */
|
|
|
|
mutex_lock(&priv->recv_mutex);
|
|
|
|
|
|
|
|
/* Grab the message off the list. */
|
|
|
|
spin_lock_irqsave(&(priv->recv_msg_lock), flags);
|
|
|
|
if (list_empty(&(priv->recv_msgs))) {
|
|
|
|
spin_unlock_irqrestore(&(priv->recv_msg_lock), flags);
|
|
|
|
rv = -EAGAIN;
|
|
|
|
goto recv_err;
|
|
|
|
}
|
|
|
|
entry = priv->recv_msgs.next;
|
|
|
|
msg = list_entry(entry, struct ipmi_recv_msg, link);
|
|
|
|
list_del(entry);
|
|
|
|
spin_unlock_irqrestore(&(priv->recv_msg_lock), flags);
|
|
|
|
|
|
|
|
addr_len = ipmi_addr_length(msg->addr.addr_type);
|
|
|
|
if (rsp->addr_len < addr_len)
|
|
|
|
{
|
|
|
|
rv = -EINVAL;
|
|
|
|
goto recv_putback_on_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (copy_to_user(rsp->addr, &(msg->addr), addr_len)) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
goto recv_putback_on_err;
|
|
|
|
}
|
|
|
|
rsp->addr_len = addr_len;
|
|
|
|
|
|
|
|
rsp->recv_type = msg->recv_type;
|
|
|
|
rsp->msgid = msg->msgid;
|
|
|
|
rsp->msg.netfn = msg->msg.netfn;
|
|
|
|
rsp->msg.cmd = msg->msg.cmd;
|
|
|
|
|
|
|
|
if (msg->msg.data_len > 0) {
|
|
|
|
if (rsp->msg.data_len < msg->msg.data_len) {
|
|
|
|
rv = -EMSGSIZE;
|
|
|
|
if (trunc)
|
|
|
|
msg->msg.data_len = rsp->msg.data_len;
|
|
|
|
else
|
|
|
|
goto recv_putback_on_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (copy_to_user(rsp->msg.data,
|
|
|
|
msg->msg.data,
|
|
|
|
msg->msg.data_len))
|
|
|
|
{
|
|
|
|
rv = -EFAULT;
|
|
|
|
goto recv_putback_on_err;
|
|
|
|
}
|
|
|
|
rsp->msg.data_len = msg->msg.data_len;
|
|
|
|
} else {
|
|
|
|
rsp->msg.data_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = copyout(rsp, to);
|
|
|
|
if (rv)
|
|
|
|
goto recv_putback_on_err;
|
|
|
|
|
|
|
|
mutex_unlock(&priv->recv_mutex);
|
|
|
|
ipmi_free_recv_msg(msg);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
recv_putback_on_err:
|
|
|
|
/* If we got an error, put the message back onto
|
|
|
|
the head of the queue. */
|
|
|
|
spin_lock_irqsave(&(priv->recv_msg_lock), flags);
|
|
|
|
list_add(entry, &(priv->recv_msgs));
|
|
|
|
spin_unlock_irqrestore(&(priv->recv_msg_lock), flags);
|
|
|
|
recv_err:
|
|
|
|
mutex_unlock(&priv->recv_mutex);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int copyout_recv(struct ipmi_recv *rsp, void __user *to)
|
|
|
|
{
|
|
|
|
return copy_to_user(to, rsp, sizeof(struct ipmi_recv)) ? -EFAULT : 0;
|
|
|
|
}
|
|
|
|
|
2010-04-27 06:24:05 +08:00
|
|
|
static int ipmi_ioctl(struct file *file,
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int cmd,
|
|
|
|
unsigned long data)
|
|
|
|
{
|
|
|
|
int rv = -EINVAL;
|
|
|
|
struct ipmi_file_private *priv = file->private_data;
|
|
|
|
void __user *arg = (void __user *)data;
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case IPMICTL_SEND_COMMAND:
|
|
|
|
{
|
|
|
|
struct ipmi_req req;
|
|
|
|
|
|
|
|
if (copy_from_user(&req, arg, sizeof(req))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = handle_send_req(priv->user,
|
|
|
|
&req,
|
|
|
|
priv->default_retries,
|
|
|
|
priv->default_retry_time_ms);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IPMICTL_SEND_COMMAND_SETTIME:
|
|
|
|
{
|
|
|
|
struct ipmi_req_settime req;
|
|
|
|
|
|
|
|
if (copy_from_user(&req, arg, sizeof(req))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = handle_send_req(priv->user,
|
|
|
|
&req.req,
|
|
|
|
req.retries,
|
|
|
|
req.retry_time_ms);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IPMICTL_RECEIVE_MSG:
|
|
|
|
case IPMICTL_RECEIVE_MSG_TRUNC:
|
|
|
|
{
|
|
|
|
struct ipmi_recv rsp;
|
|
|
|
|
2017-06-27 04:47:01 +08:00
|
|
|
if (copy_from_user(&rsp, arg, sizeof(rsp)))
|
2005-04-17 06:20:36 +08:00
|
|
|
rv = -EFAULT;
|
2017-06-27 04:47:01 +08:00
|
|
|
else
|
|
|
|
rv = handle_recv(priv, cmd == IPMICTL_RECEIVE_MSG_TRUNC,
|
|
|
|
&rsp, copyout_recv, arg);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IPMICTL_REGISTER_FOR_CMD:
|
|
|
|
{
|
|
|
|
struct ipmi_cmdspec val;
|
|
|
|
|
|
|
|
if (copy_from_user(&val, arg, sizeof(val))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-10-01 14:27:56 +08:00
|
|
|
rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd,
|
|
|
|
IPMI_CHAN_ALL);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IPMICTL_UNREGISTER_FOR_CMD:
|
|
|
|
{
|
|
|
|
struct ipmi_cmdspec val;
|
|
|
|
|
|
|
|
if (copy_from_user(&val, arg, sizeof(val))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-10-01 14:27:56 +08:00
|
|
|
rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd,
|
|
|
|
IPMI_CHAN_ALL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IPMICTL_REGISTER_FOR_CMD_CHANS:
|
|
|
|
{
|
|
|
|
struct ipmi_cmdspec_chans val;
|
|
|
|
|
|
|
|
if (copy_from_user(&val, arg, sizeof(val))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd,
|
|
|
|
val.chans);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IPMICTL_UNREGISTER_FOR_CMD_CHANS:
|
|
|
|
{
|
|
|
|
struct ipmi_cmdspec_chans val;
|
|
|
|
|
|
|
|
if (copy_from_user(&val, arg, sizeof(val))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd,
|
|
|
|
val.chans);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IPMICTL_SET_GETS_EVENTS_CMD:
|
|
|
|
{
|
|
|
|
int val;
|
|
|
|
|
|
|
|
if (copy_from_user(&val, arg, sizeof(val))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = ipmi_set_gets_events(priv->user, val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-09-07 06:18:38 +08:00
|
|
|
/* The next four are legacy, not per-channel. */
|
2005-04-17 06:20:36 +08:00
|
|
|
case IPMICTL_SET_MY_ADDRESS_CMD:
|
|
|
|
{
|
|
|
|
unsigned int val;
|
|
|
|
|
|
|
|
if (copy_from_user(&val, arg, sizeof(val))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-09-07 06:18:38 +08:00
|
|
|
rv = ipmi_set_my_address(priv->user, 0, val);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IPMICTL_GET_MY_ADDRESS_CMD:
|
|
|
|
{
|
2005-09-07 06:18:38 +08:00
|
|
|
unsigned int val;
|
|
|
|
unsigned char rval;
|
|
|
|
|
|
|
|
rv = ipmi_get_my_address(priv->user, 0, &rval);
|
|
|
|
if (rv)
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-07 06:18:38 +08:00
|
|
|
val = rval;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (copy_to_user(arg, &val, sizeof(val))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IPMICTL_SET_MY_LUN_CMD:
|
|
|
|
{
|
|
|
|
unsigned int val;
|
|
|
|
|
|
|
|
if (copy_from_user(&val, arg, sizeof(val))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-09-07 06:18:38 +08:00
|
|
|
rv = ipmi_set_my_LUN(priv->user, 0, val);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IPMICTL_GET_MY_LUN_CMD:
|
|
|
|
{
|
2005-09-07 06:18:38 +08:00
|
|
|
unsigned int val;
|
|
|
|
unsigned char rval;
|
|
|
|
|
|
|
|
rv = ipmi_get_my_LUN(priv->user, 0, &rval);
|
|
|
|
if (rv)
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-07 06:18:38 +08:00
|
|
|
val = rval;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (copy_to_user(arg, &val, sizeof(val))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-09-07 06:18:38 +08:00
|
|
|
|
|
|
|
case IPMICTL_SET_MY_CHANNEL_ADDRESS_CMD:
|
|
|
|
{
|
|
|
|
struct ipmi_channel_lun_address_set val;
|
|
|
|
|
|
|
|
if (copy_from_user(&val, arg, sizeof(val))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ipmi_set_my_address(priv->user, val.channel, val.value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IPMICTL_GET_MY_CHANNEL_ADDRESS_CMD:
|
|
|
|
{
|
|
|
|
struct ipmi_channel_lun_address_set val;
|
|
|
|
|
|
|
|
if (copy_from_user(&val, arg, sizeof(val))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = ipmi_get_my_address(priv->user, val.channel, &val.value);
|
|
|
|
if (rv)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (copy_to_user(arg, &val, sizeof(val))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IPMICTL_SET_MY_CHANNEL_LUN_CMD:
|
|
|
|
{
|
|
|
|
struct ipmi_channel_lun_address_set val;
|
|
|
|
|
|
|
|
if (copy_from_user(&val, arg, sizeof(val))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = ipmi_set_my_LUN(priv->user, val.channel, val.value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IPMICTL_GET_MY_CHANNEL_LUN_CMD:
|
|
|
|
{
|
|
|
|
struct ipmi_channel_lun_address_set val;
|
|
|
|
|
|
|
|
if (copy_from_user(&val, arg, sizeof(val))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = ipmi_get_my_LUN(priv->user, val.channel, &val.value);
|
|
|
|
if (rv)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (copy_to_user(arg, &val, sizeof(val))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
case IPMICTL_SET_TIMING_PARMS_CMD:
|
|
|
|
{
|
|
|
|
struct ipmi_timing_parms parms;
|
|
|
|
|
|
|
|
if (copy_from_user(&parms, arg, sizeof(parms))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->default_retries = parms.retries;
|
|
|
|
priv->default_retry_time_ms = parms.retry_time_ms;
|
|
|
|
rv = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IPMICTL_GET_TIMING_PARMS_CMD:
|
|
|
|
{
|
|
|
|
struct ipmi_timing_parms parms;
|
|
|
|
|
|
|
|
parms.retries = priv->default_retries;
|
|
|
|
parms.retry_time_ms = priv->default_retry_time_ms;
|
|
|
|
|
|
|
|
if (copy_to_user(arg, &parms, sizeof(parms))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = 0;
|
|
|
|
break;
|
|
|
|
}
|
2006-12-07 12:41:02 +08:00
|
|
|
|
|
|
|
case IPMICTL_GET_MAINTENANCE_MODE_CMD:
|
|
|
|
{
|
|
|
|
int mode;
|
|
|
|
|
|
|
|
mode = ipmi_get_maintenance_mode(priv->user);
|
|
|
|
if (copy_to_user(arg, &mode, sizeof(mode))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rv = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IPMICTL_SET_MAINTENANCE_MODE_CMD:
|
|
|
|
{
|
|
|
|
int mode;
|
|
|
|
|
|
|
|
if (copy_from_user(&mode, arg, sizeof(mode))) {
|
|
|
|
rv = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rv = ipmi_set_maintenance_mode(priv->user, mode);
|
|
|
|
break;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-04-27 06:24:05 +08:00
|
|
|
/*
|
|
|
|
* Note: it doesn't make sense to take the BKL here but
|
|
|
|
* not in compat_ipmi_ioctl. -arnd
|
|
|
|
*/
|
|
|
|
static long ipmi_unlocked_ioctl(struct file *file,
|
|
|
|
unsigned int cmd,
|
|
|
|
unsigned long data)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2010-06-02 20:28:52 +08:00
|
|
|
mutex_lock(&ipmi_mutex);
|
2010-04-27 06:24:05 +08:00
|
|
|
ret = ipmi_ioctl(file, cmd, data);
|
2010-06-02 20:28:52 +08:00
|
|
|
mutex_unlock(&ipmi_mutex);
|
2010-04-27 06:24:05 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-06-24 13:01:45 +08:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following code contains code for supporting 32-bit compatible
|
|
|
|
* ioctls on 64-bit kernels. This allows running 32-bit apps on the
|
|
|
|
* 64-bit kernel
|
|
|
|
*/
|
|
|
|
#define COMPAT_IPMICTL_SEND_COMMAND \
|
|
|
|
_IOR(IPMI_IOC_MAGIC, 13, struct compat_ipmi_req)
|
|
|
|
#define COMPAT_IPMICTL_SEND_COMMAND_SETTIME \
|
|
|
|
_IOR(IPMI_IOC_MAGIC, 21, struct compat_ipmi_req_settime)
|
|
|
|
#define COMPAT_IPMICTL_RECEIVE_MSG \
|
|
|
|
_IOWR(IPMI_IOC_MAGIC, 12, struct compat_ipmi_recv)
|
|
|
|
#define COMPAT_IPMICTL_RECEIVE_MSG_TRUNC \
|
|
|
|
_IOWR(IPMI_IOC_MAGIC, 11, struct compat_ipmi_recv)
|
|
|
|
|
|
|
|
struct compat_ipmi_msg {
|
|
|
|
u8 netfn;
|
|
|
|
u8 cmd;
|
|
|
|
u16 data_len;
|
|
|
|
compat_uptr_t data;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct compat_ipmi_req {
|
|
|
|
compat_uptr_t addr;
|
|
|
|
compat_uint_t addr_len;
|
|
|
|
compat_long_t msgid;
|
|
|
|
struct compat_ipmi_msg msg;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct compat_ipmi_recv {
|
|
|
|
compat_int_t recv_type;
|
|
|
|
compat_uptr_t addr;
|
|
|
|
compat_uint_t addr_len;
|
|
|
|
compat_long_t msgid;
|
|
|
|
struct compat_ipmi_msg msg;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct compat_ipmi_req_settime {
|
|
|
|
struct compat_ipmi_req req;
|
|
|
|
compat_int_t retries;
|
|
|
|
compat_uint_t retry_time_ms;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define some helper functions for copying IPMI data
|
|
|
|
*/
|
2017-06-27 05:02:54 +08:00
|
|
|
static void get_compat_ipmi_msg(struct ipmi_msg *p64,
|
|
|
|
struct compat_ipmi_msg *p32)
|
2005-06-24 13:01:45 +08:00
|
|
|
{
|
2017-06-27 05:02:54 +08:00
|
|
|
p64->netfn = p32->netfn;
|
|
|
|
p64->cmd = p32->cmd;
|
|
|
|
p64->data_len = p32->data_len;
|
|
|
|
p64->data = compat_ptr(p32->data);
|
2005-06-24 13:01:45 +08:00
|
|
|
}
|
|
|
|
|
2017-06-27 05:02:54 +08:00
|
|
|
static void get_compat_ipmi_req(struct ipmi_req *p64,
|
|
|
|
struct compat_ipmi_req *p32)
|
2005-06-24 13:01:45 +08:00
|
|
|
{
|
2017-06-27 05:02:54 +08:00
|
|
|
p64->addr = compat_ptr(p32->addr);
|
|
|
|
p64->addr_len = p32->addr_len;
|
|
|
|
p64->msgid = p32->msgid;
|
|
|
|
get_compat_ipmi_msg(&p64->msg, &p32->msg);
|
2005-06-24 13:01:45 +08:00
|
|
|
}
|
|
|
|
|
2017-06-27 05:02:54 +08:00
|
|
|
static void get_compat_ipmi_req_settime(struct ipmi_req_settime *p64,
|
|
|
|
struct compat_ipmi_req_settime *p32)
|
2005-06-24 13:01:45 +08:00
|
|
|
{
|
2017-06-27 05:02:54 +08:00
|
|
|
get_compat_ipmi_req(&p64->req, &p32->req);
|
|
|
|
p64->retries = p32->retries;
|
|
|
|
p64->retry_time_ms = p32->retry_time_ms;
|
2005-06-24 13:01:45 +08:00
|
|
|
}
|
|
|
|
|
2017-06-27 05:02:54 +08:00
|
|
|
static void get_compat_ipmi_recv(struct ipmi_recv *p64,
|
|
|
|
struct compat_ipmi_recv *p32)
|
2005-06-24 13:01:45 +08:00
|
|
|
{
|
2017-06-27 05:02:54 +08:00
|
|
|
memset(p64, 0, sizeof(struct ipmi_recv));
|
|
|
|
p64->recv_type = p32->recv_type;
|
|
|
|
p64->addr = compat_ptr(p32->addr);
|
|
|
|
p64->addr_len = p32->addr_len;
|
|
|
|
p64->msgid = p32->msgid;
|
|
|
|
get_compat_ipmi_msg(&p64->msg, &p32->msg);
|
2005-06-24 13:01:45 +08:00
|
|
|
}
|
|
|
|
|
2017-06-27 04:47:01 +08:00
|
|
|
static int copyout_recv32(struct ipmi_recv *p64, void __user *to)
|
2005-06-24 13:01:45 +08:00
|
|
|
{
|
2017-06-27 04:47:01 +08:00
|
|
|
struct compat_ipmi_recv v32;
|
|
|
|
memset(&v32, 0, sizeof(struct compat_ipmi_recv));
|
|
|
|
v32.recv_type = p64->recv_type;
|
|
|
|
v32.addr = ptr_to_compat(p64->addr);
|
|
|
|
v32.addr_len = p64->addr_len;
|
|
|
|
v32.msgid = p64->msgid;
|
|
|
|
v32.msg.netfn = p64->msg.netfn;
|
|
|
|
v32.msg.cmd = p64->msg.cmd;
|
|
|
|
v32.msg.data_len = p64->msg.data_len;
|
|
|
|
v32.msg.data = ptr_to_compat(p64->msg.data);
|
|
|
|
return copy_to_user(to, &v32, sizeof(v32)) ? -EFAULT : 0;
|
2005-06-24 13:01:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle compatibility ioctls
|
|
|
|
*/
|
|
|
|
static long compat_ipmi_ioctl(struct file *filep, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
struct ipmi_file_private *priv = filep->private_data;
|
|
|
|
|
|
|
|
switch(cmd) {
|
|
|
|
case COMPAT_IPMICTL_SEND_COMMAND:
|
|
|
|
{
|
|
|
|
struct ipmi_req rp;
|
2017-06-27 05:02:54 +08:00
|
|
|
struct compat_ipmi_req r32;
|
2005-06-24 13:01:45 +08:00
|
|
|
|
2017-06-27 05:02:54 +08:00
|
|
|
if (copy_from_user(&r32, compat_ptr(arg), sizeof(r32)))
|
2005-06-24 13:01:45 +08:00
|
|
|
return -EFAULT;
|
|
|
|
|
2017-06-27 05:02:54 +08:00
|
|
|
get_compat_ipmi_req(&rp, &r32);
|
|
|
|
|
2005-06-24 13:01:45 +08:00
|
|
|
return handle_send_req(priv->user, &rp,
|
|
|
|
priv->default_retries,
|
|
|
|
priv->default_retry_time_ms);
|
|
|
|
}
|
|
|
|
case COMPAT_IPMICTL_SEND_COMMAND_SETTIME:
|
|
|
|
{
|
|
|
|
struct ipmi_req_settime sp;
|
2017-06-27 05:02:54 +08:00
|
|
|
struct compat_ipmi_req_settime sp32;
|
2005-06-24 13:01:45 +08:00
|
|
|
|
2017-06-27 05:02:54 +08:00
|
|
|
if (copy_from_user(&sp32, compat_ptr(arg), sizeof(sp32)))
|
2005-06-24 13:01:45 +08:00
|
|
|
return -EFAULT;
|
|
|
|
|
2017-06-27 05:02:54 +08:00
|
|
|
get_compat_ipmi_req_settime(&sp, &sp32);
|
|
|
|
|
2005-06-24 13:01:45 +08:00
|
|
|
return handle_send_req(priv->user, &sp.req,
|
|
|
|
sp.retries, sp.retry_time_ms);
|
|
|
|
}
|
|
|
|
case COMPAT_IPMICTL_RECEIVE_MSG:
|
|
|
|
case COMPAT_IPMICTL_RECEIVE_MSG_TRUNC:
|
|
|
|
{
|
2005-09-10 03:14:05 +08:00
|
|
|
struct ipmi_recv recv64;
|
2017-06-27 05:02:54 +08:00
|
|
|
struct compat_ipmi_recv recv32;
|
2005-06-24 13:01:45 +08:00
|
|
|
|
2017-06-27 05:02:54 +08:00
|
|
|
if (copy_from_user(&recv32, compat_ptr(arg), sizeof(recv32)))
|
2005-06-24 13:01:45 +08:00
|
|
|
return -EFAULT;
|
|
|
|
|
2017-06-27 05:02:54 +08:00
|
|
|
get_compat_ipmi_recv(&recv64, &recv32);
|
|
|
|
|
2017-06-27 04:47:01 +08:00
|
|
|
return handle_recv(priv,
|
|
|
|
cmd == COMPAT_IPMICTL_RECEIVE_MSG_TRUNC,
|
|
|
|
&recv64, copyout_recv32, compat_ptr(arg));
|
2005-06-24 13:01:45 +08:00
|
|
|
}
|
|
|
|
default:
|
2010-04-27 06:24:05 +08:00
|
|
|
return ipmi_ioctl(filep, cmd, arg);
|
2005-06-24 13:01:45 +08:00
|
|
|
}
|
|
|
|
}
|
2013-05-17 03:04:27 +08:00
|
|
|
|
|
|
|
static long unlocked_compat_ipmi_ioctl(struct file *filep, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&ipmi_mutex);
|
|
|
|
ret = compat_ipmi_ioctl(filep, cmd, arg);
|
|
|
|
mutex_unlock(&ipmi_mutex);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2005-06-24 13:01:45 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-03 15:24:21 +08:00
|
|
|
static const struct file_operations ipmi_fops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.owner = THIS_MODULE,
|
2010-04-27 06:24:05 +08:00
|
|
|
.unlocked_ioctl = ipmi_unlocked_ioctl,
|
2005-06-24 13:01:45 +08:00
|
|
|
#ifdef CONFIG_COMPAT
|
2013-05-17 03:04:27 +08:00
|
|
|
.compat_ioctl = unlocked_compat_ipmi_ioctl,
|
2005-06-24 13:01:45 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
.open = ipmi_open,
|
|
|
|
.release = ipmi_release,
|
|
|
|
.fasync = ipmi_fasync,
|
|
|
|
.poll = ipmi_poll,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-16 00:52:59 +08:00
|
|
|
.llseek = noop_llseek,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define DEVICE_NAME "ipmidev"
|
|
|
|
|
2006-12-10 18:19:06 +08:00
|
|
|
static int ipmi_major;
|
2005-04-17 06:20:36 +08:00
|
|
|
module_param(ipmi_major, int, 0);
|
|
|
|
MODULE_PARM_DESC(ipmi_major, "Sets the major number of the IPMI device. By"
|
|
|
|
" default, or if you set it to zero, it will choose the next"
|
|
|
|
" available device. Setting it to -1 will disable the"
|
|
|
|
" interface. Other values will set the major device number"
|
|
|
|
" to that value.");
|
|
|
|
|
2006-03-26 17:37:21 +08:00
|
|
|
/* Keep track of the devices that are registered. */
|
|
|
|
struct ipmi_reg_list {
|
|
|
|
dev_t dev;
|
|
|
|
struct list_head link;
|
|
|
|
};
|
|
|
|
static LIST_HEAD(reg_list);
|
|
|
|
static DEFINE_MUTEX(reg_list_mutex);
|
|
|
|
|
2005-05-06 06:06:38 +08:00
|
|
|
static struct class *ipmi_class;
|
2005-05-20 14:56:23 +08:00
|
|
|
|
2006-03-26 17:37:21 +08:00
|
|
|
static void ipmi_new_smi(int if_num, struct device *device)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-05-20 14:56:23 +08:00
|
|
|
dev_t dev = MKDEV(ipmi_major, if_num);
|
2006-03-26 17:37:21 +08:00
|
|
|
struct ipmi_reg_list *entry;
|
2005-05-20 14:56:23 +08:00
|
|
|
|
2006-03-26 17:37:21 +08:00
|
|
|
entry = kmalloc(sizeof(*entry), GFP_KERNEL);
|
|
|
|
if (!entry) {
|
|
|
|
printk(KERN_ERR "ipmi_devintf: Unable to create the"
|
|
|
|
" ipmi class device link\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
entry->dev = dev;
|
|
|
|
|
|
|
|
mutex_lock(®_list_mutex);
|
2008-07-22 11:03:34 +08:00
|
|
|
device_create(ipmi_class, device, dev, NULL, "ipmi%d", if_num);
|
2006-03-26 17:37:21 +08:00
|
|
|
list_add(&entry->link, ®_list);
|
|
|
|
mutex_unlock(®_list_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ipmi_smi_gone(int if_num)
|
|
|
|
{
|
2006-03-26 17:37:21 +08:00
|
|
|
dev_t dev = MKDEV(ipmi_major, if_num);
|
|
|
|
struct ipmi_reg_list *entry;
|
|
|
|
|
|
|
|
mutex_lock(®_list_mutex);
|
|
|
|
list_for_each_entry(entry, ®_list, link) {
|
|
|
|
if (entry->dev == dev) {
|
|
|
|
list_del(&entry->link);
|
|
|
|
kfree(entry);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-08-08 13:28:44 +08:00
|
|
|
device_destroy(ipmi_class, dev);
|
2006-03-26 17:37:21 +08:00
|
|
|
mutex_unlock(®_list_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct ipmi_smi_watcher smi_watcher =
|
|
|
|
{
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.new_smi = ipmi_new_smi,
|
|
|
|
.smi_gone = ipmi_smi_gone,
|
|
|
|
};
|
|
|
|
|
2010-10-28 06:34:18 +08:00
|
|
|
static int __init init_ipmi_devintf(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
if (ipmi_major < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2005-09-07 06:18:42 +08:00
|
|
|
printk(KERN_INFO "ipmi device interface\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-05-06 06:06:38 +08:00
|
|
|
ipmi_class = class_create(THIS_MODULE, "ipmi");
|
2005-05-20 14:56:23 +08:00
|
|
|
if (IS_ERR(ipmi_class)) {
|
|
|
|
printk(KERN_ERR "ipmi: can't register device class\n");
|
|
|
|
return PTR_ERR(ipmi_class);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
rv = register_chrdev(ipmi_major, DEVICE_NAME, &ipmi_fops);
|
|
|
|
if (rv < 0) {
|
2005-05-06 06:06:38 +08:00
|
|
|
class_destroy(ipmi_class);
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_ERR "ipmi: can't get major %d\n", ipmi_major);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ipmi_major == 0) {
|
|
|
|
ipmi_major = rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = ipmi_smi_watcher_register(&smi_watcher);
|
|
|
|
if (rv) {
|
|
|
|
unregister_chrdev(ipmi_major, DEVICE_NAME);
|
2005-05-06 06:06:38 +08:00
|
|
|
class_destroy(ipmi_class);
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_WARNING "ipmi: can't register smi watcher\n");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
module_init(init_ipmi_devintf);
|
|
|
|
|
2010-10-28 06:34:18 +08:00
|
|
|
static void __exit cleanup_ipmi(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-03-26 17:37:21 +08:00
|
|
|
struct ipmi_reg_list *entry, *entry2;
|
|
|
|
mutex_lock(®_list_mutex);
|
|
|
|
list_for_each_entry_safe(entry, entry2, ®_list, link) {
|
|
|
|
list_del(&entry->link);
|
2007-08-08 13:28:44 +08:00
|
|
|
device_destroy(ipmi_class, entry->dev);
|
2006-03-26 17:37:21 +08:00
|
|
|
kfree(entry);
|
|
|
|
}
|
|
|
|
mutex_unlock(®_list_mutex);
|
2005-05-06 06:06:38 +08:00
|
|
|
class_destroy(ipmi_class);
|
2005-04-17 06:20:36 +08:00
|
|
|
ipmi_smi_watcher_unregister(&smi_watcher);
|
|
|
|
unregister_chrdev(ipmi_major, DEVICE_NAME);
|
|
|
|
}
|
|
|
|
module_exit(cleanup_ipmi);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
2005-09-07 06:18:42 +08:00
|
|
|
MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>");
|
|
|
|
MODULE_DESCRIPTION("Linux device interface for the IPMI message handler.");
|