[RFC V2 PATCH] coresight: change tmc from misc device to cdev device

Leo Yan leo.yan at linaro.org
Fri Dec 17 20:21:30 PST 2021


On Fri, Dec 17, 2021 at 10:18:59AM -0700, Mathieu Poirier wrote:

[...]

> > > @@ -618,7 +632,43 @@ static struct amba_driver tmc_driver = {
> > >  	.id_table	= tmc_ids,
> > >  };
> > >  
> > > -module_amba_driver(tmc_driver);

[...]

> > > +static int __init tmc_init(void)
> > > +{
> > > +	int ret;
> > > +
> > > +	ret = alloc_chrdev_region(&tmc_major, 0, TMC_DEV_MAX, "tmc");
> > > +	if (ret < 0) {
> > > +		pr_err("tmc: failed to allocate char dev region\n");
> > > +		return ret;
> > > +	}
> > > +
> > > +	tmc_class = class_create(THIS_MODULE, "tmc");
> > > +	if (IS_ERR(tmc_class)) {
> > > +		pr_err("failed to create tmc class\n");
> > > +		ret = PTR_ERR(tmc_class);
> > > +		unregister_chrdev_region(tmc_major, TMC_DEV_MAX);
> > > +		return ret;
> > > +	}
> > > +
> > > +	ret = amba_driver_register(&tmc_driver);
> > > +	if (ret) {
> > > +		pr_err("tmc: error registering amba driver\n");
> > > +		class_destroy(tmc_class);
> > > +		unregister_chrdev_region(tmc_major, TMC_DEV_MAX);
> > > +	}
> > > +
> > > +	return ret;
> > > +}

[...]

> > > +module_init(tmc_init);
> > 
> > Should invoke tmc_init() in an ealier phase so it can prepare device class
> > prior to the TMC devices registration?  In other words, I think here
> > should be:
> > 
> >   subsys_initcall(tmc_init);
> 
> TMC devices won't be registered until a TMC driver is registered, which happens
> after the creation of the class.  Anything I am missing?

No, I introduced noise and sorry for that.

The race condition between creating TMC class (subsystem) and TMC driver
probing has been handled well by this patch.

It removes "module_amba_driver(tmc_driver)", then in tmc_init(), uses
amba_driver_register() to register TMC driver.  So that can ensure the
TMC class has been created prior to TMC driver registeration and TMC
driver probing.

Please ignore my comment for using subsys_initcall().

Thanks,
Leo



More information about the linux-arm-kernel mailing list