relay: require non-NULL callbacks in relay_open()
[linux-block.git] / kernel / relay.c
index b08d936d5fa75b58651ad40192d42373c5ff773c..d9b8185161a89ce7316cc3f8f2f7c7258133385c 100644 (file)
 static DEFINE_MUTEX(relay_channels_mutex);
 static LIST_HEAD(relay_channels);
 
-/*
- * close() vm_op implementation for relay file mapping.
- */
-static void relay_file_mmap_close(struct vm_area_struct *vma)
-{
-       struct rchan_buf *buf = vma->vm_private_data;
-       buf->chan->cb->buf_unmapped(buf, vma->vm_file);
-}
-
 /*
  * fault() vm_op implementation for relay file mapping.
  */
@@ -62,7 +53,6 @@ static vm_fault_t relay_buf_fault(struct vm_fault *vmf)
  */
 static const struct vm_operations_struct relay_file_mmap_ops = {
        .fault = relay_buf_fault,
-       .close = relay_file_mmap_close,
 };
 
 /*
@@ -96,7 +86,6 @@ static void relay_free_page_array(struct page **array)
 static int relay_mmap_buf(struct rchan_buf *buf, struct vm_area_struct *vma)
 {
        unsigned long length = vma->vm_end - vma->vm_start;
-       struct file *filp = vma->vm_file;
 
        if (!buf)
                return -EBADF;
@@ -107,7 +96,6 @@ static int relay_mmap_buf(struct rchan_buf *buf, struct vm_area_struct *vma)
        vma->vm_ops = &relay_file_mmap_ops;
        vma->vm_flags |= VM_DONTEXPAND;
        vma->vm_private_data = buf;
-       buf->chan->cb->buf_mapped(buf, filp);
 
        return 0;
 }
@@ -283,22 +271,6 @@ static int subbuf_start_default_callback (struct rchan_buf *buf,
        return 1;
 }
 
-/*
- * buf_mapped() default callback.  Does nothing.
- */
-static void buf_mapped_default_callback(struct rchan_buf *buf,
-                                       struct file *filp)
-{
-}
-
-/*
- * buf_unmapped() default callback.  Does nothing.
- */
-static void buf_unmapped_default_callback(struct rchan_buf *buf,
-                                         struct file *filp)
-{
-}
-
 /*
  * create_buf_file_create() default callback.  Does nothing.
  */
@@ -319,15 +291,6 @@ static int remove_buf_file_default_callback(struct dentry *dentry)
        return -EINVAL;
 }
 
-/* relay channel default callbacks */
-static struct rchan_callbacks default_channel_callbacks = {
-       .subbuf_start = subbuf_start_default_callback,
-       .buf_mapped = buf_mapped_default_callback,
-       .buf_unmapped = buf_unmapped_default_callback,
-       .create_buf_file = create_buf_file_default_callback,
-       .remove_buf_file = remove_buf_file_default_callback,
-};
-
 /**
  *     wakeup_readers - wake up readers waiting on a channel
  *     @work: contains the channel buffer
@@ -502,17 +465,8 @@ static void relay_close_buf(struct rchan_buf *buf)
 static void setup_callbacks(struct rchan *chan,
                                   struct rchan_callbacks *cb)
 {
-       if (!cb) {
-               chan->cb = &default_channel_callbacks;
-               return;
-       }
-
        if (!cb->subbuf_start)
                cb->subbuf_start = subbuf_start_default_callback;
-       if (!cb->buf_mapped)
-               cb->buf_mapped = buf_mapped_default_callback;
-       if (!cb->buf_unmapped)
-               cb->buf_unmapped = buf_unmapped_default_callback;
        if (!cb->create_buf_file)
                cb->create_buf_file = create_buf_file_default_callback;
        if (!cb->remove_buf_file)
@@ -576,6 +530,8 @@ struct rchan *relay_open(const char *base_filename,
                return NULL;
        if (subbuf_size > UINT_MAX / n_subbufs)
                return NULL;
+       if (!cb)
+               return NULL;
 
        chan = kzalloc(sizeof(struct rchan), GFP_KERNEL);
        if (!chan)