Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3340968pxj; Mon, 24 May 2021 04:38:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXAwxMtqz99Q1Z0Tj26uvSWDQRSY0B8HGE2x7xOzAT2I8RTOdjGIStf1jRNsksHdpD/ZeW X-Received: by 2002:a17:906:9812:: with SMTP id lm18mr22753925ejb.428.1621856290418; Mon, 24 May 2021 04:38:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621856290; cv=none; d=google.com; s=arc-20160816; b=bDwgGMKEDoi+VknYPyXv4NAbPFfA1E493isaJ9su/43xet+vkjYlxH5JSsfptj4CtS sTjzEcACms6KPwt7NGmE/OS/aE2My747AbFg5OeIwOX7jxeGaacjBOJjLvrAMiNzEjfR angRni1KII5n7BNSLVFwW/af/V0Rh0oH9fbfhegTRpN31KonWtyVFV4RL8+t/OhzSnAO jL+XFtCa/+O/Ld5Q2WIWkU99mVJiPFDLJSmlT+HnXOgosLtFOQoahnHI3v1m6lKMFFYp eYAN5AKzvROs+ZU29gxTj5+mP04UQyijNGXeFkGWOxph90GGIz7HxeJmpVHoMp92/NeX 1tYw== 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=WVxW9vMS7TMNZcrvjkJd5wBEoOFqR7RRMnokt+Y2Fb8=; b=pZW8OOrEYiHKU7ff1US5pHEabOKXeQzuO6yeSHP+lTL0AYgJ9/wIUqj7GNwzwT5rUu ijvwfM74FALr+W7i0mdDZk3fyVbRwIcT1/0tCYmufqAVS5wlcWvDFtspTH4gBchZmsdA tap0Ex6KjxjWeqWd+cMWYR+YBMmTnGBOpRAUSIULdyN9IjNxtVePFCiW50YkvxSkqsUn f8siOcVW6RqyL/oJ1D2MDy0Dj1NInvydwijMm1uqYWyAjVecOrVNB3RpDLH6m6sxK09I tafawCTHzFvA04iRVcP7Yc517mU/TVEBekSWn+ugn6PKCr8TZN6cwE8hdUkqHPg+FOJ/ GdpA== 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 w2si14996019edi.531.2021.05.24.04.37.47; Mon, 24 May 2021 04:38:10 -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 S232802AbhEXLhR (ORCPT + 99 others); Mon, 24 May 2021 07:37:17 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:3646 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232719AbhEXLhM (ORCPT ); Mon, 24 May 2021 07:37:12 -0400 Received: from dggems706-chm.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FpZn43JPrzNyhx; Mon, 24 May 2021 19:32:08 +0800 (CST) Received: from dggpemm500009.china.huawei.com (7.185.36.225) by dggems706-chm.china.huawei.com (10.3.19.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 24 May 2021 19:35:43 +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; Mon, 24 May 2021 19:35:43 +0800 From: Liu Shixin To: Mike Isely , Mauro Carvalho Chehab CC: , , Liu Shixin Subject: [PATCH -next] [media] media: Replaced simple_strtol() with kstrtoint() Date: Mon, 24 May 2021 20:08:36 +0800 Message-ID: <20210524120836.1580468-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 --- 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