본문 바로가기

Core BSP 분석/커널 트러블슈팅

[patch] Sample code to fix crash when unloading drivers

diff --git a/sound/soc/codecs/wcd-kdt_sample-v2.c b/sound/soc/codecs/wcd-kdt_sample-v2.c
index dba66e5..22b38ec 100644
--- a/sound/soc/codecs/wcd-kdt_sample-v2.c
+++ b/sound/soc/codecs/wcd-kdt_sample-v2.c
@@ -2484,9 +2484,6 @@
 {
  struct snd_soc_codec *codec = kdt_sample->codec;
 
-#ifdef CONFIG_KDT_RPI_SAMPLE 
- switch_dev_unregister(&kdt_sample->sdev);
-#endif //CONFIG_KDT_RPI_SAMPLE
  kdt_sample->kdt_sample_cb->free_irq(codec, kdt_sample->intr_ids->kdt_sample_sw_intr, kdt_sample);
  kdt_sample->kdt_sample_cb->free_irq(codec, kdt_sample->intr_ids->kdt_sample_btn_press_intr,
  kdt_sample);
@@ -2496,6 +2493,14 @@
  kdt_sample->kdt_sample_cb->free_irq(codec, kdt_sample->intr_ids->kdt_sample_hs_rem_intr, kdt_sample);
  kdt_sample->kdt_sample_cb->free_irq(codec, kdt_sample->intr_ids->hph_left_ocp, kdt_sample);
  kdt_sample->kdt_sample_cb->free_irq(codec, kdt_sample->intr_ids->hph_right_ocp, kdt_sample);
+#ifdef CONFIG_KDT_RPI_SAMPLE  
+ //switch_dev_unregister(&kdt_sample->sdev);
+ if (kdt_sample->sdev.name){
+     switch_dev_unregister(&kdt_sample->sdev);
+ memset(&kdt_sample->sdev, 0, sizeof(struct switch_dev));
+
+ }
+#endif //CONFIG_KDT_RPI_SAMPLE
  if (kdt_sample->kdt_sample_cb && kdt_sample->kdt_sample_cb->register_notifier)
  kdt_sample->kdt_sample_cb->register_notifier(codec, &kdt_sample->nblock, false);
  mutex_destroy(&kdt_sample->codec_resource_lock);