From 479ffdf8425de523a653fb7fad8fa207b495e254 Mon Sep 17 00:00:00 2001 From: Cao Jian Date: Fri, 17 Jul 2020 14:18:22 +0800 Subject: [PATCH] gdc: add a probed flag to avoid crash [1/1] PD#SWPL-29848 Problem: on platforms which GDC are not supported if create_gdc_work_queue is invoked a crash occurs Solution: add a probed flag to avoid crash add a interface is_gdc_supported to query Verify: g12b/tm2 Change-Id: I65b88294822d8a2c7429d375039fee962b9612aa Signed-off-by: Cao Jian --- drivers/amlogic/media/gdc/app/gdc_module.c | 2 ++ drivers/amlogic/media/gdc/app/gdc_wq.c | 13 +++++++++++++ drivers/amlogic/media/gdc/inc/gdc/gdc_config.h | 1 + include/linux/amlogic/media/gdc/gdc.h | 3 ++- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/amlogic/media/gdc/app/gdc_module.c b/drivers/amlogic/media/gdc/app/gdc_module.c index 1dd5eb9bf573..7933c576b739 100644 --- a/drivers/amlogic/media/gdc/app/gdc_module.c +++ b/drivers/amlogic/media/gdc/app/gdc_module.c @@ -1900,6 +1900,8 @@ static int gdc_platform_probe(struct platform_device *pdev) platform_set_drvdata(pdev, gdc_dev); gdc_pwr_config(false); + gdc_manager.probed = 1; + return rc; } diff --git a/drivers/amlogic/media/gdc/app/gdc_wq.c b/drivers/amlogic/media/gdc/app/gdc_wq.c index f2fb62f7ee2b..29180925a851 100644 --- a/drivers/amlogic/media/gdc/app/gdc_wq.c +++ b/drivers/amlogic/media/gdc/app/gdc_wq.c @@ -324,6 +324,15 @@ static inline int work_queue_no_space(struct gdc_context_s *queue) return list_empty(&queue->free_queue); } +bool is_gdc_supported(void) +{ + if (gdc_manager.probed) + return true; + + return false; +} +EXPORT_SYMBOL(is_gdc_supported); + struct gdc_context_s *create_gdc_work_queue(void) { int i; @@ -331,6 +340,10 @@ struct gdc_context_s *create_gdc_work_queue(void) struct gdc_context_s *gdc_work_queue; int empty; + if (!gdc_manager.probed) { + gdc_log(LOG_INFO, "GDC is not supported for this chip\n"); + return NULL; + } gdc_work_queue = kzalloc(sizeof(struct gdc_context_s), GFP_KERNEL); if (IS_ERR(gdc_work_queue)) { gdc_log(LOG_ERR, "can't create work queue\n"); diff --git a/drivers/amlogic/media/gdc/inc/gdc/gdc_config.h b/drivers/amlogic/media/gdc/inc/gdc/gdc_config.h index 866b2756f7c1..5cc598b0e27b 100644 --- a/drivers/amlogic/media/gdc/inc/gdc/gdc_config.h +++ b/drivers/amlogic/media/gdc/inc/gdc/gdc_config.h @@ -56,6 +56,7 @@ struct gdc_manager_s { int gdc_state; int process_queue_state;//thread running flag struct meson_gdc_dev_t *gdc_dev; + int probed; }; extern struct gdc_manager_s gdc_manager; diff --git a/include/linux/amlogic/media/gdc/gdc.h b/include/linux/amlogic/media/gdc/gdc.h index 15c9faa9f07b..42c4b80c0c4b 100644 --- a/include/linux/amlogic/media/gdc/gdc.h +++ b/include/linux/amlogic/media/gdc/gdc.h @@ -165,9 +165,10 @@ struct gdc_phy_setting { char config_name[CONFIG_PATH_LENG]; }; +bool is_gdc_supported(void); +struct gdc_context_s *create_gdc_work_queue(void); int gdc_process_phys(struct gdc_context_s *context, struct gdc_phy_setting *gs); -struct gdc_context_s *create_gdc_work_queue(void); int destroy_gdc_work_queue(struct gdc_context_s *gdc_work_queue); #endif