mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-17 02:15:57 +00:00
ff62b8e658
The devnode() in struct class should not be modifying the device that is passed into it, so mark it as a const * and propagate the function signature changes out into all relevant subsystems that use this callback. Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Reinette Chatre <reinette.chatre@intel.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: x86@kernel.org Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Cc: Jens Axboe <axboe@kernel.dk> Cc: Justin Sanders <justin@coraid.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Sumit Semwal <sumit.semwal@linaro.org> Cc: Benjamin Gaignard <benjamin.gaignard@collabora.com> Cc: Liam Mark <lmark@codeaurora.org> Cc: Laura Abbott <labbott@redhat.com> Cc: Brian Starkey <Brian.Starkey@arm.com> Cc: John Stultz <jstultz@google.com> Cc: "Christian König" <christian.koenig@amd.com> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Cc: Maxime Ripard <mripard@kernel.org> Cc: Thomas Zimmermann <tzimmermann@suse.de> Cc: David Airlie <airlied@gmail.com> Cc: Daniel Vetter <daniel@ffwll.ch> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: Leon Romanovsky <leon@kernel.org> Cc: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com> Cc: Mauro Carvalho Chehab <mchehab@kernel.org> Cc: Sean Young <sean@mess.org> Cc: Frank Haverkamp <haver@linux.ibm.com> Cc: Jiri Slaby <jirislaby@kernel.org> Cc: "Michael S. Tsirkin" <mst@redhat.com> Cc: Jason Wang <jasowang@redhat.com> Cc: Alex Williamson <alex.williamson@redhat.com> Cc: Cornelia Huck <cohuck@redhat.com> Cc: Kees Cook <keescook@chromium.org> Cc: Anton Vorontsov <anton@enomsg.org> Cc: Colin Cross <ccross@android.com> Cc: Tony Luck <tony.luck@intel.com> Cc: Jaroslav Kysela <perex@perex.cz> Cc: Takashi Iwai <tiwai@suse.com> Cc: Hans Verkuil <hverkuil-cisco@xs4all.nl> Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Cc: Xie Yongji <xieyongji@bytedance.com> Cc: Gautam Dawar <gautam.dawar@xilinx.com> Cc: Dan Carpenter <error27@gmail.com> Cc: Eli Cohen <elic@nvidia.com> Cc: Parav Pandit <parav@nvidia.com> Cc: Maxime Coquelin <maxime.coquelin@redhat.com> Cc: alsa-devel@alsa-project.org Cc: dri-devel@lists.freedesktop.org Cc: kvm@vger.kernel.org Cc: linaro-mm-sig@lists.linaro.org Cc: linux-block@vger.kernel.org Cc: linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-media@vger.kernel.org Cc: linux-rdma@vger.kernel.org Cc: linux-scsi@vger.kernel.org Cc: linux-usb@vger.kernel.org Cc: virtualization@lists.linux-foundation.org Link: https://lore.kernel.org/r/20221123122523.1332370-2-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
95 lines
1.9 KiB
C
95 lines
1.9 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright 2014 Google, Inc.
|
|
*/
|
|
|
|
#include <linux/cdev.h>
|
|
#include <linux/device.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/uaccess.h>
|
|
#include "internal.h"
|
|
|
|
static DEFINE_MUTEX(pmsg_lock);
|
|
|
|
static ssize_t write_pmsg(struct file *file, const char __user *buf,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct pstore_record record;
|
|
int ret;
|
|
|
|
if (!count)
|
|
return 0;
|
|
|
|
pstore_record_init(&record, psinfo);
|
|
record.type = PSTORE_TYPE_PMSG;
|
|
record.size = count;
|
|
|
|
/* check outside lock, page in any data. write_user also checks */
|
|
if (!access_ok(buf, count))
|
|
return -EFAULT;
|
|
|
|
mutex_lock(&pmsg_lock);
|
|
ret = psinfo->write_user(&record, buf);
|
|
mutex_unlock(&pmsg_lock);
|
|
return ret ? ret : count;
|
|
}
|
|
|
|
static const struct file_operations pmsg_fops = {
|
|
.owner = THIS_MODULE,
|
|
.llseek = noop_llseek,
|
|
.write = write_pmsg,
|
|
};
|
|
|
|
static struct class *pmsg_class;
|
|
static int pmsg_major;
|
|
#define PMSG_NAME "pmsg"
|
|
#undef pr_fmt
|
|
#define pr_fmt(fmt) PMSG_NAME ": " fmt
|
|
|
|
static char *pmsg_devnode(const struct device *dev, umode_t *mode)
|
|
{
|
|
if (mode)
|
|
*mode = 0220;
|
|
return NULL;
|
|
}
|
|
|
|
void pstore_register_pmsg(void)
|
|
{
|
|
struct device *pmsg_device;
|
|
|
|
pmsg_major = register_chrdev(0, PMSG_NAME, &pmsg_fops);
|
|
if (pmsg_major < 0) {
|
|
pr_err("register_chrdev failed\n");
|
|
goto err;
|
|
}
|
|
|
|
pmsg_class = class_create(THIS_MODULE, PMSG_NAME);
|
|
if (IS_ERR(pmsg_class)) {
|
|
pr_err("device class file already in use\n");
|
|
goto err_class;
|
|
}
|
|
pmsg_class->devnode = pmsg_devnode;
|
|
|
|
pmsg_device = device_create(pmsg_class, NULL, MKDEV(pmsg_major, 0),
|
|
NULL, "%s%d", PMSG_NAME, 0);
|
|
if (IS_ERR(pmsg_device)) {
|
|
pr_err("failed to create device\n");
|
|
goto err_device;
|
|
}
|
|
return;
|
|
|
|
err_device:
|
|
class_destroy(pmsg_class);
|
|
err_class:
|
|
unregister_chrdev(pmsg_major, PMSG_NAME);
|
|
err:
|
|
return;
|
|
}
|
|
|
|
void pstore_unregister_pmsg(void)
|
|
{
|
|
device_destroy(pmsg_class, MKDEV(pmsg_major, 0));
|
|
class_destroy(pmsg_class);
|
|
unregister_chrdev(pmsg_major, PMSG_NAME);
|
|
}
|