Subject: [PATCH] driver: gpu: add failure check for ftell

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



add return-value check of ftell to improve robustness(and avoid abnormal behavior)

Signed-off-by: SPeak <speakshen@xxxxxxx>
Signed-off-by: shenyanfeng <shenyanfeng@xxxxxxxxxx>
---
 drivers/gpu/drm/radeon/mkregtable.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
index 52a7246fe..c31c58e5f 100644
--- a/drivers/gpu/drm/radeon/mkregtable.c
+++ b/drivers/gpu/drm/radeon/mkregtable.c
@@ -193,6 +193,7 @@ static int parser_auth(struct table *t, const char *filename)
  regmatch_t match[4];
  char buf[1024];
  size_t end;
+ long pos;
  int len;
  int done = 0;
  int r;
@@ -228,12 +229,12 @@ static int parser_auth(struct table *t, const char *filename)
  last_reg = strtol(last_reg_s, NULL, 16);
 
  do {
- if (fgets(buf, 1024, file) == NULL) {
+ if ((fgets(buf, 1024, file) == NULL) || (pos = ftell(file)) < 0) {
  fclose(file);
  return -1;
  }
  len = strlen(buf);
- if (ftell(file) == end)
+ if (pos == end)
  done = 1;
  if (len) {
  r = regexec(&mask_rex, buf, 4, match, 0);
-- 
2.37.2

#/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#

[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux