From patchwork Tue Jun 23 08:11:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Seymour, Shane M" X-Patchwork-Id: 6659211 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EBA319F380 for ; Tue, 23 Jun 2015 08:12:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1382E20614 for ; Tue, 23 Jun 2015 08:12:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D5006204EA for ; Tue, 23 Jun 2015 08:12:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932276AbbFWIMT (ORCPT ); Tue, 23 Jun 2015 04:12:19 -0400 Received: from g4t3427.houston.hp.com ([15.201.208.55]:55559 "EHLO g4t3427.houston.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932213AbbFWIMC convert rfc822-to-8bit (ORCPT ); Tue, 23 Jun 2015 04:12:02 -0400 Received: from G9W0364.americas.hpqcorp.net (g9w0364.houston.hp.com [16.216.193.45]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by g4t3427.houston.hp.com (Postfix) with ESMTPS id 21E6720A; Tue, 23 Jun 2015 08:12:02 +0000 (UTC) Received: from G9W3613.americas.hpqcorp.net (16.216.186.48) by G9W0364.americas.hpqcorp.net (16.216.193.45) with Microsoft SMTP Server (TLS) id 14.3.169.1; Tue, 23 Jun 2015 08:11:00 +0000 Received: from G9W0766.americas.hpqcorp.net ([169.254.4.103]) by G9W3613.americas.hpqcorp.net ([16.216.186.48]) with mapi id 14.03.0169.001; Tue, 23 Jun 2015 08:11:00 +0000 From: "Seymour, Shane M" To: "linux-scsi@vger.kernel.org" , "Kai.Makisara@kolumbus.fi" CC: "linux-api@vger.kernel.org" Subject: [PATCH] st: convert to using driver attr groups for sysfs Thread-Topic: [PATCH] st: convert to using driver attr groups for sysfs Thread-Index: AdCtisOhglmVPiaXSHaTL55TNglCtg== Date: Tue, 23 Jun 2015 08:11:00 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [16.210.48.16] MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: Greg Kroah-Hartman Acked-by: Kai Mäkisara --- -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/drivers/scsi/st.c 2015-06-22 14:20:40.829612661 -0500 +++ b/drivers/scsi/st.c 2015-06-22 15:49:49.357248393 -0500 @@ -85,6 +85,7 @@ static int debug_flag; static struct class st_sysfs_class; static const struct attribute_group *st_dev_groups[]; +static const struct attribute_group *st_drv_groups[]; MODULE_AUTHOR("Kai Makisara"); MODULE_DESCRIPTION("SCSI tape (st) driver"); @@ -198,15 +199,13 @@ static int sgl_unmap_user_pages(struct s static int st_probe(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 = { .gendrv = { .name = "st", .owner = THIS_MODULE, .probe = st_probe, .remove = st_remove, + .groups = st_drv_groups, }, }; @@ -4404,14 +4403,8 @@ static int __init init_st(void) if (err) goto err_chrdev; - err = do_create_sysfs_files(); - if (err) - goto err_scsidrv; - return 0; -err_scsidrv: - scsi_unregister_driver(&st_template.gendrv); err_chrdev: unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0), ST_MAX_TAPE_ENTRIES); @@ -4422,7 +4415,6 @@ err_class: static void __exit exit_st(void) { - do_remove_sysfs_files(); scsi_unregister_driver(&st_template.gendrv); unregister_chrdev_region(MKDEV(SCSI_TAPE_MAJOR, 0), ST_MAX_TAPE_ENTRIES); @@ -4459,44 +4451,14 @@ static ssize_t st_version_show(struct de } static DRIVER_ATTR(version, S_IRUGO, st_version_show, NULL); -static int do_create_sysfs_files(void) -{ - struct device_driver *sysfs = &st_template.gendrv; - int err; - - err = driver_create_file(sysfs, &driver_attr_try_direct_io); - if (err) - return err; - 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); -} +static struct attribute *st_drv_attrs[] = { + &driver_attr_try_direct_io.attr, + &driver_attr_fixed_buffer_size.attr, + &driver_attr_max_sg_segs.attr, + &driver_attr_version.attr, + NULL, +}; +ATTRIBUTE_GROUPS(st_drv); /* The sysfs simple class interface */ static ssize_t