st: convert to using driver attr groups for sysfs
This patch changes the st driver to use attribute groups so driver sysfs files are created automatically. See the following for reference: http://kroah.com/log/blog/2013/06/26/how-to-create-a-sysfs-file-correctly/ Signed-off-by: Shane Seymour <shane.seymour@hp.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Acked-by: Kai Mäkisara <kai.makisara@kolumbus.fi> Signed-off-by: James Bottomley <JBottomley@Odin.com>
This commit is contained in:
parent
3ff448b5b7
commit
442d75628a
|
@ -85,6 +85,7 @@ static int debug_flag;
|
||||||
|
|
||||||
static struct class st_sysfs_class;
|
static struct class st_sysfs_class;
|
||||||
static const struct attribute_group *st_dev_groups[];
|
static const struct attribute_group *st_dev_groups[];
|
||||||
|
static const struct attribute_group *st_drv_groups[];
|
||||||
|
|
||||||
MODULE_AUTHOR("Kai Makisara");
|
MODULE_AUTHOR("Kai Makisara");
|
||||||
MODULE_DESCRIPTION("SCSI tape (st) driver");
|
MODULE_DESCRIPTION("SCSI tape (st) driver");
|
||||||
|
@ -198,15 +199,13 @@ static int sgl_unmap_user_pages(struct st_buffer *, const unsigned int, int);
|
||||||
static int st_probe(struct device *);
|
static int st_probe(struct device *);
|
||||||
static int st_remove(struct device *);
|
static int st_remove(struct device *);
|
||||||
|
|
||||||
static int do_create_sysfs_files(void);
|
|
||||||
static void do_remove_sysfs_files(void);
|
|
||||||
|
|
||||||
static struct scsi_driver st_template = {
|
static struct scsi_driver st_template = {
|
||||||
.gendrv = {
|
.gendrv = {
|
||||||
.name = "st",
|
.name = "st",
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.probe = st_probe,
|
.probe = st_probe,
|
||||||
.remove = st_remove,
|
.remove = st_remove,
|
||||||
|
.groups = st_drv_groups,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4404,14 +4403,8 @@ static int __init init_st(void)
|
||||||
if (err)
|
if (err)
|
||||||
goto err_chrdev;
|
goto err_chrdev;
|
||||||
|
|
||||||
err = do_create_sysfs_files();
|
|
||||||
if (err)
|
|
||||||
goto err_scsidrv;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_scsidrv:
|
|
||||||
scsi_unregister_driver(&st_template.gendrv);
|
|
||||||
err_chrdev:
|
err_chrdev:
|
||||||
unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0),
|
unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0),
|
||||||
ST_MAX_TAPE_ENTRIES);
|
ST_MAX_TAPE_ENTRIES);
|
||||||
|
@ -4422,7 +4415,6 @@ err_class:
|
||||||
|
|
||||||
static void __exit exit_st(void)
|
static void __exit exit_st(void)
|
||||||
{
|
{
|
||||||
do_remove_sysfs_files();
|
|
||||||
scsi_unregister_driver(&st_template.gendrv);
|
scsi_unregister_driver(&st_template.gendrv);
|
||||||
unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0),
|
unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0),
|
||||||
ST_MAX_TAPE_ENTRIES);
|
ST_MAX_TAPE_ENTRIES);
|
||||||
|
@ -4459,44 +4451,14 @@ static ssize_t st_version_show(struct device_driver *ddd, char *buf)
|
||||||
}
|
}
|
||||||
static DRIVER_ATTR(version, S_IRUGO, st_version_show, NULL);
|
static DRIVER_ATTR(version, S_IRUGO, st_version_show, NULL);
|
||||||
|
|
||||||
static int do_create_sysfs_files(void)
|
static struct attribute *st_drv_attrs[] = {
|
||||||
{
|
&driver_attr_try_direct_io.attr,
|
||||||
struct device_driver *sysfs = &st_template.gendrv;
|
&driver_attr_fixed_buffer_size.attr,
|
||||||
int err;
|
&driver_attr_max_sg_segs.attr,
|
||||||
|
&driver_attr_version.attr,
|
||||||
err = driver_create_file(sysfs, &driver_attr_try_direct_io);
|
NULL,
|
||||||
if (err)
|
};
|
||||||
return err;
|
ATTRIBUTE_GROUPS(st_drv);
|
||||||
err = driver_create_file(sysfs, &driver_attr_fixed_buffer_size);
|
|
||||||
if (err)
|
|
||||||
goto err_try_direct_io;
|
|
||||||
err = driver_create_file(sysfs, &driver_attr_max_sg_segs);
|
|
||||||
if (err)
|
|
||||||
goto err_attr_fixed_buf;
|
|
||||||
err = driver_create_file(sysfs, &driver_attr_version);
|
|
||||||
if (err)
|
|
||||||
goto err_attr_max_sg;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
err_attr_max_sg:
|
|
||||||
driver_remove_file(sysfs, &driver_attr_max_sg_segs);
|
|
||||||
err_attr_fixed_buf:
|
|
||||||
driver_remove_file(sysfs, &driver_attr_fixed_buffer_size);
|
|
||||||
err_try_direct_io:
|
|
||||||
driver_remove_file(sysfs, &driver_attr_try_direct_io);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void do_remove_sysfs_files(void)
|
|
||||||
{
|
|
||||||
struct device_driver *sysfs = &st_template.gendrv;
|
|
||||||
|
|
||||||
driver_remove_file(sysfs, &driver_attr_version);
|
|
||||||
driver_remove_file(sysfs, &driver_attr_max_sg_segs);
|
|
||||||
driver_remove_file(sysfs, &driver_attr_fixed_buffer_size);
|
|
||||||
driver_remove_file(sysfs, &driver_attr_try_direct_io);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The sysfs simple class interface */
|
/* The sysfs simple class interface */
|
||||||
static ssize_t
|
static ssize_t
|
||||||
|
|
Loading…
Reference in New Issue