Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp512063pxj; Thu, 27 May 2021 05:45:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyS/sd0f5z7So9/a11IGkxp7a3NTcXZXpAF3Iz62pCdskjT+s/TDsnG9AyucZ0DhTSACsLB X-Received: by 2002:a5d:93d9:: with SMTP id j25mr2556381ioo.102.1622119521695; Thu, 27 May 2021 05:45:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622119521; cv=none; d=google.com; s=arc-20160816; b=MW2jHDgNj7pUMUrt+Tv52FUfsoaumpzcb/H0+rAVVtY5cM7ZkKacj3z9nZsrBh3Rvq sUqFt8EiP9wYEfA0cpQpTRWRvHk4W8GuVNMYsxnIq5bheRSnjJWbvASPYU2Wz4gm9JB1 22DD/jL9VYl3dJM+hxrs/ft1o6MzJIhw48FyZl6A5S7tf+ZNm4SLpTEAvHWLnynjDE3t yjHYwoaT9nDcGPN/58pDXBOMNaMUJFWaSUY6V2jod9+ed4A1FL9x/CWLOGgx+RYqOJQa Fz/WqDCpUJjc0yWk20VTKe94MZsTk6oAbpjTSmlUgZYC8DaGm8KLqorDKADDMjyacT/s eY2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=nDqKmOVRvS9mKj6GHezd+3zpVOXKixcuVBa9IBzv1aE=; b=jAthTEg8qNhhfUtj5OPyOYbPIYsEtiqC5EAgy5UHzlbIoi4cW90Xj0eTEWwc2Q5vfz NDBATocvzg9JlKhRFEDuy5FspZmPUot/xcm2CQO9cNLL6GL3k/MSWpvrMEeSfHb+bhvB Iv5apQOU1rQffn+QcdtPlcHlO6iTiy1rnv9M8aCnx5k8qAIYZKhMJ32p0Y2pn85E+dd1 +JoMMcvO3BJc1WbUFq7yD7BDbMMoyHG8Y0s0SneJYJdOxR+WhYYerEsJuJdWq75apNgc kv33ve5VnKv7ySw6Sc8Waeh/PHRjhunm3QzrrwlR9yoaCbI223EiJ8PNmtcQQl/ZEImq 1F4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s6si2342886jao.56.2021.05.27.05.45.07; Thu, 27 May 2021 05:45:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235634AbhE0Mpw (ORCPT + 99 others); Thu, 27 May 2021 08:45:52 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:2372 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235206AbhE0Mpv (ORCPT ); Thu, 27 May 2021 08:45:51 -0400 Received: from dggeml763-chm.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4FrS8h6ktqz66BJ; Thu, 27 May 2021 20:40:36 +0800 (CST) Received: from dggpemm500009.china.huawei.com (7.185.36.225) by dggeml763-chm.china.huawei.com (10.1.199.173) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Thu, 27 May 2021 20:44:15 +0800 Received: from huawei.com (10.175.113.32) by dggpemm500009.china.huawei.com (7.185.36.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 27 May 2021 20:44:14 +0800 From: Liu Shixin To: Mike Isely , Mauro Carvalho Chehab , Hans Verkuil CC: , , Liu Shixin Subject: [PATCH -next v2] media: pvrusb2: Replaced simple_strtol() with kstrtoint() Date: Thu, 27 May 2021 21:17:01 +0800 Message-ID: <20210527131701.3779497-1-liushixin2@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It looks like that memcpy() is a superfluous operation in parse_token()/parse_mtoken(). Simple these two functions and use kstrtoint() instead of simple_strtol() to avoid data overflow. Signed-off-by: Liu Shixin --- v1->v2: Fix subject line suggested by Hans. Thanks to Hans for advice. drivers/media/usb/pvrusb2/pvrusb2-ctrl.c | 25 ++---------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/drivers/media/usb/pvrusb2/pvrusb2-ctrl.c b/drivers/media/usb/pvrusb2/pvrusb2-ctrl.c index 9f71d8c2a3c6..8ae3ad80cccb 100644 --- a/drivers/media/usb/pvrusb2/pvrusb2-ctrl.c +++ b/drivers/media/usb/pvrusb2/pvrusb2-ctrl.c @@ -355,11 +355,8 @@ static int parse_token(const char *ptr,unsigned int len, int *valptr, const char * const *names, unsigned int namecnt) { - char buf[33]; unsigned int slen; unsigned int idx; - int negfl; - char *p2; *valptr = 0; if (!names) namecnt = 0; for (idx = 0; idx < namecnt; idx++) { @@ -370,18 +367,7 @@ static int parse_token(const char *ptr,unsigned int len, *valptr = idx; return 0; } - negfl = 0; - if ((*ptr == '-') || (*ptr == '+')) { - negfl = (*ptr == '-'); - ptr++; len--; - } - if (len >= sizeof(buf)) return -EINVAL; - memcpy(buf,ptr,len); - buf[len] = 0; - *valptr = simple_strtol(buf,&p2,0); - if (negfl) *valptr = -(*valptr); - if (*p2) return -EINVAL; - return 1; + return kstrtoint(ptr, 0, valptr) ? -EINVAL : 1; } @@ -389,10 +375,8 @@ static int parse_mtoken(const char *ptr,unsigned int len, int *valptr, const char **names,int valid_bits) { - char buf[33]; unsigned int slen; unsigned int idx; - char *p2; int msk; *valptr = 0; for (idx = 0, msk = 1; valid_bits; idx++, msk <<= 1) { @@ -405,12 +389,7 @@ static int parse_mtoken(const char *ptr,unsigned int len, *valptr = msk; return 0; } - if (len >= sizeof(buf)) return -EINVAL; - memcpy(buf,ptr,len); - buf[len] = 0; - *valptr = simple_strtol(buf,&p2,0); - if (*p2) return -EINVAL; - return 0; + return kstrtoint(ptr, 0, valptr); } -- 2.18.0.huawei.25