Message ID | 20200731064012.8076-22-tingwei@codeaurora.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | coresight: allow to build coresight as modules | expand |
Please see my comment from the previous patch regarding the function here. Mike On Fri, 31 Jul 2020 at 07:42, Tingwei Zhang <tingwei@codeaurora.org> wrote: > > CTI device is enabled when associated coresight device is enabled. > Increase the module and device reference count for CTI device > when it's enabled. This can prevent CTI device be removed or > module be unloaded when CTI device is enabled by an active trace > session. > > Signed-off-by: Mike Leach <mike.leach@linaro.org> > Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org> > --- > drivers/hwtracing/coresight/coresight.c | 17 ++++++++++++++--- > 1 file changed, 14 insertions(+), 3 deletions(-) > > diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c > index 83a46cf37968..78439b7cd8ba 100644 > --- a/drivers/hwtracing/coresight/coresight.c > +++ b/drivers/hwtracing/coresight/coresight.c > @@ -242,19 +242,30 @@ coresight_control_assoc_ectdev(struct coresight_device *csdev, bool enable) > { > int ect_ret = 0; > struct coresight_device *ect_csdev = csdev->ect_dev; > + struct module *mod; > > if (!ect_csdev) > return 0; > if ((!ect_ops(ect_csdev)->enable) || (!ect_ops(ect_csdev)->disable)) > return 0; > > + mod = ect_csdev->dev.parent->driver->owner; > if (enable) { > - ect_ret = ect_ops(ect_csdev)->enable(ect_csdev); > - if (ect_ret) > - csdev->ect_enabled = true; > + if (try_module_get(mod)) { > + ect_ret = ect_ops(ect_csdev)->enable(ect_csdev); > + if (ect_ret) { > + module_put(mod); > + } else { > + get_device(ect_csdev->dev.parent); > + csdev->ect_enabled = true; > + } > + } else > + ect_ret = -ENODEV; > } else { > if (csdev->ect_enabled) { > ect_ret = ect_ops(ect_csdev)->disable(ect_csdev); > + put_device(ect_csdev->dev.parent); > + module_put(mod); > csdev->ect_enabled = false; > } > } > -- > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, > a Linux Foundation Collaborative Project > -- Mike Leach Principal Engineer, ARM Ltd. Manchester Design Centre. UK
diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index 83a46cf37968..78439b7cd8ba 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -242,19 +242,30 @@ coresight_control_assoc_ectdev(struct coresight_device *csdev, bool enable) { int ect_ret = 0; struct coresight_device *ect_csdev = csdev->ect_dev; + struct module *mod; if (!ect_csdev) return 0; if ((!ect_ops(ect_csdev)->enable) || (!ect_ops(ect_csdev)->disable)) return 0; + mod = ect_csdev->dev.parent->driver->owner; if (enable) { - ect_ret = ect_ops(ect_csdev)->enable(ect_csdev); - if (ect_ret) - csdev->ect_enabled = true; + if (try_module_get(mod)) { + ect_ret = ect_ops(ect_csdev)->enable(ect_csdev); + if (ect_ret) { + module_put(mod); + } else { + get_device(ect_csdev->dev.parent); + csdev->ect_enabled = true; + } + } else + ect_ret = -ENODEV; } else { if (csdev->ect_enabled) { ect_ret = ect_ops(ect_csdev)->disable(ect_csdev); + put_device(ect_csdev->dev.parent); + module_put(mod); csdev->ect_enabled = false; } }