Skip to content

Commit 30054dc

Browse files
Evoke Zhangakiernan
Evoke Zhang
authored andcommitted
vout: driver defect clean up
PD#150476: driver defect clean up: torvalds#115 torvalds#597 torvalds#607 torvalds#609 torvalds#845 Change-Id: I92f0366ff00c8bd5e684db80c20000635256f612 Signed-off-by: Evoke Zhang <[email protected]>
1 parent 8a9c5ea commit 30054dc

File tree

4 files changed

+89
-61
lines changed

4 files changed

+89
-61
lines changed

drivers/amlogic/media/vout/vout_serve/vout_notify.c

+25-8
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,9 @@ EXPORT_SYMBOL(get_vframe_match);
235235
int set_vframe_rate_hint(int duration)
236236
{
237237
int r = -1;
238-
struct vout_server_s *p_server;
238+
struct vout_server_s *p_server = vout_module.curr_vout_server;
239239

240-
list_for_each_entry(p_server, &vout_module.vout_server_list, list) {
240+
if (p_server) {
241241
if ((p_server->op.set_vframe_rate_hint != NULL) &&
242242
(p_server->op.set_vframe_rate_hint(duration) == 0)) {
243243
return 0;
@@ -254,9 +254,9 @@ EXPORT_SYMBOL(set_vframe_rate_hint);
254254
int set_vframe_rate_end_hint(void)
255255
{
256256
int ret = -1;
257-
struct vout_server_s *p_server;
257+
struct vout_server_s *p_server = vout_module.curr_vout_server;
258258

259-
list_for_each_entry(p_server, &vout_module.vout_server_list, list) {
259+
if (p_server) {
260260
if ((p_server->op.set_vframe_rate_end_hint != NULL) &&
261261
(p_server->op.set_vframe_rate_end_hint() == 0)) {
262262
return 0;
@@ -273,9 +273,9 @@ EXPORT_SYMBOL(set_vframe_rate_end_hint);
273273
int set_vframe_rate_policy(int policy)
274274
{
275275
int ret = -1;
276-
struct vout_server_s *p_server;
276+
struct vout_server_s *p_server = vout_module.curr_vout_server;
277277

278-
list_for_each_entry(p_server, &vout_module.vout_server_list, list) {
278+
if (p_server) {
279279
if ((p_server->op.set_vframe_rate_policy != NULL) &&
280280
(p_server->op.set_vframe_rate_policy(policy) == 0)) {
281281
return 0;
@@ -292,9 +292,9 @@ EXPORT_SYMBOL(set_vframe_rate_policy);
292292
int get_vframe_rate_policy(void)
293293
{
294294
int ret = -1;
295-
struct vout_server_s *p_server;
295+
struct vout_server_s *p_server = vout_module.curr_vout_server;
296296

297-
list_for_each_entry(p_server, &vout_module.vout_server_list, list) {
297+
if (p_server) {
298298
if (p_server->op.get_vframe_rate_policy != NULL) {
299299
ret = p_server->op.get_vframe_rate_policy();
300300
return ret;
@@ -423,6 +423,23 @@ enum vmode_e validate_vmode(char *name)
423423
}
424424
EXPORT_SYMBOL(validate_vmode);
425425

426+
/*
427+
*interface export to client who want to shutdown.
428+
*/
429+
int vout_shutdown(void)
430+
{
431+
int ret = -1;
432+
struct vout_server_s *p_server;
433+
434+
list_for_each_entry(p_server, &vout_module.vout_server_list, list) {
435+
if (p_server->op.vout_shutdown)
436+
ret = p_server->op.vout_shutdown();
437+
}
438+
439+
return ret;
440+
}
441+
EXPORT_SYMBOL(vout_shutdown);
442+
426443
/*
427444
*here we offer two functions to get and register vout module server
428445
*vout module server will set and store tvmode attributes for vout encoder

drivers/amlogic/media/vout/vout_serve/vout_serve.c

+57-53
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,23 @@ static int early_suspend_flag;
5252
static int early_resume_flag;
5353
#endif
5454

55+
#define VOUT_CDEV_NAME "display"
5556
#define VOUT_CLASS_NAME "display"
5657
#define MAX_NUMBER_PARA 10
5758

59+
#define VMODE_NAME_LEN_MAX 64
5860
static struct class *vout_class;
5961
static DEFINE_MUTEX(vout_mutex);
60-
static char vout_mode_uboot[64] __nosavedata;
61-
static char vout_mode[64] __nosavedata;
62+
static char vout_mode_uboot[VMODE_NAME_LEN_MAX] __nosavedata;
63+
static char vout_mode[VMODE_NAME_LEN_MAX] __nosavedata;
64+
static char local_name[VMODE_NAME_LEN_MAX] = {0};
6265
static u32 vout_init_vmode = VMODE_INIT_NULL;
6366
static int uboot_display;
6467

6568
static char vout_axis[64] __nosavedata;
6669

67-
static char hdmimode[64];
68-
static char cvbsmode[64];
70+
static char hdmimode[VMODE_NAME_LEN_MAX];
71+
static char cvbsmode[VMODE_NAME_LEN_MAX];
6972
static enum vmode_e last_vmode = VMODE_MAX;
7073
static int tvout_monitor_flag = 1;
7174
static unsigned int tvout_monitor_timeout_cnt = 20;
@@ -75,7 +78,7 @@ static struct delayed_work tvout_mode_work;
7578
void update_vout_mode(char *name)
7679
{
7780
if (name)
78-
snprintf(vout_mode, 60, "%s", name);
81+
snprintf(vout_mode, VMODE_NAME_LEN_MAX, "%s", name);
7982
else
8083
VOUTERR("%s: vout mode is null\n", __func__);
8184
}
@@ -93,28 +96,25 @@ char *get_vout_mode_uboot(void)
9396
}
9497
EXPORT_SYMBOL(get_vout_mode_uboot);
9598

96-
static char local_name[32] = {0};
97-
9899
static int set_vout_mode(char *name)
99100
{
100101
enum vmode_e mode;
101102
int ret = 0;
102103

103104
VOUTPR("vmode set to %s\n", name);
104105

105-
mode = validate_vmode(name);
106-
if (mode == VMODE_MAX) {
107-
VOUTERR("no matched vout mode\n");
108-
return -1;
109-
}
110-
111106
if (strcmp(name, local_name) == 0) {
112107
VOUTPR("don't set the same mode as current\n");
113108
return -1;
114109
}
115110

111+
mode = validate_vmode(name);
112+
if (mode == VMODE_MAX) {
113+
VOUTERR("no matched vout mode\n");
114+
return -1;
115+
}
116116
memset(local_name, 0, sizeof(local_name));
117-
strcpy(local_name, name);
117+
snprintf(local_name, VMODE_NAME_LEN_MAX, "%s", name);
118118

119119
vout_notifier_call_chain(VOUT_EVENT_MODE_CHANGE_PRE, &mode);
120120
ret = set_current_vmode(mode);
@@ -146,7 +146,7 @@ static int set_vout_init_mode(void)
146146
vmode = vout_init_vmode;
147147

148148
memset(local_name, 0, sizeof(local_name));
149-
strcpy(local_name, vout_mode_uboot);
149+
snprintf(local_name, VMODE_NAME_LEN_MAX, "%s", vout_mode_uboot);
150150
ret = set_current_vmode(vmode);
151151
VOUTPR("init mode %s\n", vout_mode_uboot);
152152

@@ -194,17 +194,19 @@ static int parse_para(const char *para, int para_num, int *result)
194194
static void set_vout_axis(char *para)
195195
{
196196
static struct disp_rect_s disp_rect[OSD_COUNT];
197-
char count = OSD_COUNT * 4;
197+
/* char count = OSD_COUNT * 4; */
198198
int *pt = &disp_rect[0].x;
199199
int parsed[MAX_NUMBER_PARA] = {};
200200

201201
/* parse window para */
202202
if (parse_para(para, 8, parsed) >= 4)
203203
memcpy(pt, parsed, sizeof(struct disp_rect_s) * OSD_COUNT);
204-
if ((count >= 4) && (count < 8))
205-
disp_rect[1] = disp_rect[0];
204+
/* if ((count >= 4) && (count < 8))
205+
* disp_rect[1] = disp_rect[0];
206+
*/
206207

207-
VOUTPR("osd0=> x:%d,y:%d,w:%d,h:%d\nosd1=> x:%d,y:%d,w:%d,h:%d\n",
208+
VOUTPR("osd0=> x:%d,y:%d,w:%d,h:%d\n"
209+
"osd1=> x:%d,y:%d,w:%d,h:%d\n",
208210
*pt, *(pt + 1), *(pt + 2), *(pt + 3),
209211
*(pt + 4), *(pt + 5), *(pt + 6), *(pt + 7));
210212
vout_notifier_call_chain(VOUT_EVENT_OSD_DISP_AXIS, &disp_rect[0]);
@@ -215,7 +217,7 @@ static ssize_t vout_mode_show(struct class *class,
215217
{
216218
int ret = 0;
217219

218-
ret = snprintf(buf, 64, "%s\n", vout_mode);
220+
ret = snprintf(buf, VMODE_NAME_LEN_MAX, "%s\n", vout_mode);
219221

220222
return ret;
221223
}
@@ -227,9 +229,9 @@ static ssize_t vout_mode_store(struct class *class,
227229

228230
mutex_lock(&vout_mutex);
229231
tvout_monitor_flag = 0;
230-
snprintf(mode, 64, "%s", buf);
232+
snprintf(mode, VMODE_NAME_LEN_MAX, "%s", buf);
231233
if (set_vout_mode(mode) == 0)
232-
strcpy(vout_mode, mode);
234+
snprintf(vout_mode, VMODE_NAME_LEN_MAX, "%s\n", mode);
233235
mutex_unlock(&vout_mutex);
234236
return count;
235237
}
@@ -273,15 +275,16 @@ static ssize_t vout_fr_policy_store(struct class *class,
273275

274276
mutex_lock(&vout_mutex);
275277
ret = kstrtoint(buf, 10, &policy);
276-
if (ret == 1) {
277-
ret = set_vframe_rate_policy(policy);
278-
if (ret)
279-
pr_info("%s: %d failed\n", __func__, policy);
280-
} else {
278+
if (ret) {
281279
pr_info("%s: invalid data\n", __func__);
280+
mutex_unlock(&vout_mutex);
282281
return -EINVAL;
283282
}
283+
ret = set_vframe_rate_policy(policy);
284+
if (ret)
285+
pr_info("%s: %d failed\n", __func__, policy);
284286
mutex_unlock(&vout_mutex);
287+
285288
return count;
286289
}
287290

@@ -316,7 +319,7 @@ static ssize_t vout_vinfo_show(struct class *class,
316319
info->sync_duration_num, info->sync_duration_den,
317320
info->screen_real_width, info->screen_real_height,
318321
info->video_clk, info->viu_color_fmt, info->viu_mux);
319-
len += sprintf(buf+len, "hdr_info:\n"
322+
len += sprintf(buf+len, "master_display_info:\n"
320323
" present_flag %d\n"
321324
" features 0x%x\n"
322325
" primaries 0x%x, 0x%x\n"
@@ -355,13 +358,11 @@ static ssize_t vout_mode_flag_store(struct class *class,
355358
int ret = 0;
356359

357360
ret = kstrtoint(buf, 10, &tvout_monitor_flag);
358-
if (ret == 1) {
359-
VOUTPR("%s: tvout_monitor_flag = %d\n",
360-
__func__, tvout_monitor_flag);
361-
} else {
361+
if (ret) {
362362
VOUTPR("%s: invalid data\n", __func__);
363363
return -EINVAL;
364364
}
365+
VOUTPR("%s: tvout_monitor_flag = %d\n", __func__, tvout_monitor_flag);
365366

366367
return count;
367368
}
@@ -371,8 +372,8 @@ static struct class_attribute vout_class_attrs[] = {
371372
__ATTR(axis, 0644, vout_axis_show, vout_axis_store),
372373
__ATTR(fr_policy, 0644,
373374
vout_fr_policy_show, vout_fr_policy_store),
374-
__ATTR(vinfo, 0644, vout_vinfo_show, NULL),
375-
__ATTR(mode_flag, 0644, vout_mode_flag_show, vout_mode_flag_store),
375+
__ATTR(vinfo, 0444, vout_vinfo_show, NULL),
376+
__ATTR(mode_flag, 0644, vout_mode_flag_show, vout_mode_flag_store),
376377
};
377378

378379
static int vout_create_attr(void)
@@ -399,7 +400,7 @@ static int vout_create_attr(void)
399400
/* init /sys/class/display/mode */
400401
init_mode = get_current_vinfo();
401402
if (init_mode)
402-
strcpy(vout_mode, init_mode->name);
403+
snprintf(vout_mode, VMODE_NAME_LEN_MAX, "%s", init_mode->name);
403404

404405
return ret;
405406
}
@@ -554,8 +555,10 @@ static int refresh_tvout_mode(void)
554555

555556
if (cur_vmode != last_vmode) {
556557
VOUTPR("%s: mode chang\n", __func__);
557-
if (set_vout_mode(cur_mode_str) == 0)
558-
strcpy(vout_mode, cur_mode_str);
558+
if (set_vout_mode(cur_mode_str) == 0) {
559+
snprintf(vout_mode, VMODE_NAME_LEN_MAX,
560+
"%s", cur_mode_str);
561+
}
559562
last_vmode = cur_vmode;
560563
}
561564

@@ -639,6 +642,12 @@ static int aml_vout_remove(struct platform_device *pdev)
639642
return 0;
640643
}
641644

645+
static void aml_vout_shutdown(struct platform_device *pdev)
646+
{
647+
VOUTPR("%s\n", __func__);
648+
vout_shutdown();
649+
}
650+
642651
static const struct of_device_id aml_vout_dt_match[] = {
643652
{ .compatible = "amlogic, vout",},
644653
{ },
@@ -657,6 +666,7 @@ const struct dev_pm_ops vout_pm = {
657666
static struct platform_driver vout_driver = {
658667
.probe = aml_vout_probe,
659668
.remove = aml_vout_remove,
669+
.shutdown = aml_vout_shutdown,
660670
#ifdef CONFIG_PM
661671
.suspend = aml_vout_suspend,
662672
.resume = aml_vout_resume,
@@ -674,8 +684,6 @@ static int __init vout_init_module(void)
674684
{
675685
int ret = 0;
676686

677-
/*VOUTPR("%s\n", __func__);*/
678-
679687
if (platform_driver_register(&vout_driver)) {
680688
VOUTERR("failed to register VOUT driver\n");
681689
ret = -ENODEV;
@@ -686,7 +694,6 @@ static int __init vout_init_module(void)
686694

687695
static __exit void vout_exit_module(void)
688696
{
689-
/*VOUTPR("%s\n", __func__);*/
690697
platform_driver_unregister(&vout_driver);
691698
}
692699

@@ -715,7 +722,8 @@ static void vout_init_mode_parse(char *str)
715722
uboot_display = 1;
716723
VOUTPR("%s: %d\n", str, uboot_display);
717724
return;
718-
} else if (strncmp(str, "dis", 3) == 0) { /* disable */
725+
}
726+
if (strncmp(str, "dis", 3) == 0) { /* disable */
719727
uboot_display = 0;
720728
VOUTPR("%s: %d\n", str, uboot_display);
721729
return;
@@ -725,12 +733,8 @@ static void vout_init_mode_parse(char *str)
725733
* just save the vmode_name,
726734
* convert to vmode when vout sever registered
727735
*/
728-
strcpy(vout_mode_uboot, str);
736+
snprintf(vout_mode_uboot, VMODE_NAME_LEN_MAX, "%s", str);
729737
VOUTPR("%s\n", str);
730-
731-
return;
732-
733-
VOUTERR("%s: %s\n", __func__, str);
734738
}
735739

736740
static int __init get_vout_init_mode(char *str)
@@ -770,21 +774,21 @@ __setup("vout=", get_vout_init_mode);
770774

771775
static int __init get_hdmi_mode(char *str)
772776
{
773-
strcpy(hdmimode, str);
777+
snprintf(hdmimode, VMODE_NAME_LEN_MAX, "%s", str);
774778

775-
VOUTPR("get hdmimode: %s\n", str);
776-
return 1;
779+
VOUTPR("get hdmimode: %s\n", hdmimode);
780+
return 0;
777781
}
778782
__setup("hdmimode=", get_hdmi_mode);
779783

780784
static int __init get_cvbs_mode(char *str)
781785
{
782786
if ((strncmp("480", str, 3) == 0) || (strncmp("576", str, 3) == 0))
783-
strcpy(cvbsmode, str);
787+
snprintf(cvbsmode, VMODE_NAME_LEN_MAX, "%s", str);
784788
else if (strncmp("nocvbs", str, 6) == 0)
785-
strcpy(cvbsmode, "invalid");
786-
VOUTPR("get cvbsmode: %s\n", str);
787-
return 1;
789+
snprintf(cvbsmode, VMODE_NAME_LEN_MAX, "invalid");
790+
VOUTPR("get cvbsmode: %s\n", cvbsmode);
791+
return 0;
788792
}
789793
__setup("cvbsmode=", get_cvbs_mode);
790794

0 commit comments

Comments
 (0)