From: Cheah Kok Cheong <thrust73@gmail.com>
To: Ian Abbott <abbotti@mev.co.uk>
Cc: hsweeten@visionengravers.com, gregkh@linuxfoundation.org,
devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] Staging: comedi: drivers: comedi_test: Add auto-configuration capability
Date: Wed, 15 Feb 2017 14:05:48 +0800 [thread overview]
Message-ID: <20170215060548.GA10944@linux-Precision-WorkStation-T5500> (raw)
In-Reply-To: <a5a9a523-f025-f0da-1265-7e3e507f194e@mev.co.uk>
On Mon, Feb 13, 2017 at 11:14:14AM +0000, Ian Abbott wrote:
> On 11/02/17 10:37, Cheah Kok Cheong wrote:
> >+static int __init comedi_test_init(void)
> >+{
> >+ int ret;
> >+
> >+ ret = comedi_driver_register(&waveform_driver);
> >+ if (ret) {
> >+ pr_err("comedi_test: unable to register driver\n");
> >+ return ret;
> >+ }
> >+
> >+ if (!config_mode) {
> >+ ctcls = class_create(THIS_MODULE, CLASS_NAME);
> >+ if (IS_ERR(ctcls)) {
> >+ pr_warn("comedi_test: unable to create class\n");
> >+ return ret;
> >+ }
> >+
> >+ ctdev = device_create(ctcls, NULL, MKDEV(0, 0), NULL, DEV_NAME);
> >+ if (IS_ERR(ctdev)) {
> >+ pr_warn("comedi_test: unable to create device\n");
> >+ goto clean2;
> >+ }
> >+
> >+ ret = comedi_auto_config(ctdev, &waveform_driver, 0);
> >+ if (ret) {
> >+ pr_warn("comedi_test: unable to auto-configure device\n");
> >+ goto clean;
> >+ }
> >+ }
> >+
> >+ return 0;
> >+
> >+clean:
> >+ device_destroy(ctcls, MKDEV(0, 0));
> >+clean2:
> >+ class_destroy(ctcls);
> >+
> >+ return 0;
> >+}
> >+module_init(comedi_test_init);
> >+
> >+static void __exit comedi_test_exit(void)
> >+{
> >+ comedi_auto_unconfig(ctdev);
> >+
> >+ device_destroy(ctcls, MKDEV(0, 0));
> >+
> >+ class_destroy(ctcls);
>
> If the driver init returned successfully, but failed to set-up the
> auto-configured device, the device and class will not exist at this point,
> so those three calls need to go in an 'if' statement. Perhaps you could use
> 'if (ctcls) {', and set 'ctcls = NULL;' after calling
> 'class_destroy(ctcls);' in the init function.
>
> Apart from that, it looks fine.
>
Thanks for pointing out those two pointers have to be "NULL" if
auto-configuration fails.
Please review below snippet.
Sorry for the inconvenience caused.
[ Snip ]
static int __init comedi_test_init(void)
{
int ret;
ret = comedi_driver_register(&waveform_driver);
if (ret) {
pr_err("comedi_test: unable to register driver\n");
return ret;
}
if (!config_mode) {
ctcls = class_create(THIS_MODULE, CLASS_NAME);
if (IS_ERR(ctcls)) {
pr_warn("comedi_test: unable to create class\n");
goto clean3;
}
ctdev = device_create(ctcls, NULL, MKDEV(0, 0), NULL, DEV_NAME);
if (IS_ERR(ctdev)) {
pr_warn("comedi_test: unable to create device\n");
goto clean2;
}
ret = comedi_auto_config(ctdev, &waveform_driver, 0);
if (ret) {
pr_warn("comedi_test: unable to auto-configure device\n");
goto clean;
}
}
return 0;
clean:
device_destroy(ctcls, MKDEV(0, 0));
clean2:
class_destroy(ctcls);
ctdev = NULL;
clean3:
ctcls = NULL;
return 0;
}
module_init(comedi_test_init);
static void __exit comedi_test_exit(void)
{
if (ctdev)
comedi_auto_unconfig(ctdev);
if (ctcls) {
device_destroy(ctcls, MKDEV(0, 0));
class_destroy(ctcls);
}
comedi_driver_unregister(&waveform_driver);
}
module_exit(comedi_test_exit);
[ Snip ]
Thks.
Brgds,
CheahKC
next prev parent reply other threads:[~2017-02-15 14:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-11 10:37 [PATCH v2] Staging: comedi: drivers: comedi_test: Add auto-configuration capability Cheah Kok Cheong
2017-02-13 11:14 ` Ian Abbott
2017-02-15 6:05 ` Cheah Kok Cheong [this message]
2017-02-16 10:10 ` Ian Abbott
2017-02-16 14:00 ` Cheah Kok Cheong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170215060548.GA10944@linux-Precision-WorkStation-T5500 \
--to=thrust73@gmail.com \
--cc=abbotti@mev.co.uk \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=hsweeten@visionengravers.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.