Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp67028pxu; Tue, 24 Nov 2020 19:01:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJz0kB5l0jcgLYKgPS0UFYU3GwmxnOtHOJkDwHrgU3Qxepsgh+BEg81ObjYmdTWExFKhcu9z X-Received: by 2002:a05:6402:17f0:: with SMTP id t16mr1476313edy.107.1606273265600; Tue, 24 Nov 2020 19:01:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606273265; cv=none; d=google.com; s=arc-20160816; b=xBPEXCt/GmCT2+WnPxmmPb1gjir1/3J7MA9DRPCvewWnApxeTPet/98TVW6xJf8wWL VVv3tSRbimpiFeUbwbT5lgrDj9mRHrKAUUxEOxMufW0qVzYJikEcTHOpy6n8nKuS3fLl r9vaScaLBbwNDPUhvoW6P1h3x66/E1I4RbP5Hj4JxsrzHpP43XjSeU4Roua195ijXG5P FZnHT56HahmJna1GDb/nTCWJ5EFj4T6tWoXmVCajj2SHMtMhrTSaJR++gvtWxgx2cjbO b+p7gV4w0TbSCH44gpTMNvlSnVgCY58xBHkME0X/Z3Ioe9yUk2j+2TZMmGdFiDp/VNnT ntnw== 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=3xyiumj6g/gkiofUjceZDg5Kjpts8p2jPj5vM75YDjo=; b=EhRHTXm4ku3uxoXFh/fciPWkPYdAnRINDIlx5HObS1tRburIL6ZKawCoj+zfcAROVo nh59VPmbOVJzm5Kz4M8lJAk9AzaZkqGPxUGiyIVphHMZv4SLol1C/rHdflR2GOlFNkqZ Z3xJlfmGCAHNSpecX6TkovZGhV8Wjlox638wzSjzU5MeK0MFpnSIexBgq5IImJukGM3r n8A3X+keBwJh1aN3YrAbxZvberNZOMTvvuHWIr3nkf5YxpGC0tLhNP4TDAZ81+F5Cdun Jckr7cgF+v2I4ETEfKmfRdtF2QoEno8PgNuOuRsfmoA5jtsarK48W7L+HbKNnL+azSOl SNBg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dc22si413492edb.76.2020.11.24.19.00.42; Tue, 24 Nov 2020 19:01:05 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726849AbgKYC65 (ORCPT + 99 others); Tue, 24 Nov 2020 21:58:57 -0500 Received: from pbmsgap02.intersil.com ([192.157.179.202]:34076 "EHLO pbmsgap02.intersil.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725776AbgKYC65 (ORCPT ); Tue, 24 Nov 2020 21:58:57 -0500 Received: from pps.filterd (pbmsgap02.intersil.com [127.0.0.1]) by pbmsgap02.intersil.com (8.16.0.42/8.16.0.42) with SMTP id 0AP2skCP015208; Tue, 24 Nov 2020 21:58:54 -0500 Received: from pbmxdp01.intersil.corp (pbmxdp01.pb.intersil.com [132.158.200.222]) by pbmsgap02.intersil.com with ESMTP id 34xwxkt1sh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 24 Nov 2020 21:58:54 -0500 Received: from pbmxdp02.intersil.corp (132.158.200.223) by pbmxdp01.intersil.corp (132.158.200.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.1979.3; Tue, 24 Nov 2020 21:58:53 -0500 Received: from localhost (132.158.202.109) by pbmxdp02.intersil.corp (132.158.200.223) with Microsoft SMTP Server id 15.1.1979.3 via Frontend Transport; Tue, 24 Nov 2020 21:58:52 -0500 From: To: CC: , , Min Li Subject: [PATCH v3 net] ptp: clockmatrix: bug fix for idtcm_strverscmp Date: Tue, 24 Nov 2020 21:58:35 -0500 Message-ID: <1606273115-25792-1-git-send-email-min.li.xe@renesas.com> X-Mailer: git-send-email 2.7.4 X-TM-AS-MML: disable MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-24_11:2020-11-24,2020-11-24 signatures=0 X-Proofpoint-Spam-Details: rule=junk_notspam policy=junk score=0 mlxlogscore=933 adultscore=0 spamscore=0 suspectscore=4 bulkscore=0 malwarescore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011250016 X-Proofpoint-Spam-Reason: mlx Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Min Li Feed kstrtou8 with NULL terminated string. Changes since v1: -Use sscanf to get rid of adhoc string parse. Changes since v2: -Check if sscanf returns 3. Signed-off-by: Min Li --- drivers/ptp/ptp_clockmatrix.c | 49 ++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/drivers/ptp/ptp_clockmatrix.c b/drivers/ptp/ptp_clockmatrix.c index e020faf..6632557 100644 --- a/drivers/ptp/ptp_clockmatrix.c +++ b/drivers/ptp/ptp_clockmatrix.c @@ -103,43 +103,26 @@ static int timespec_to_char_array(struct timespec64 const *ts, return 0; } -static int idtcm_strverscmp(const char *ver1, const char *ver2) +static int idtcm_strverscmp(const char *version1, const char *version2) { - u8 num1; - u8 num2; - int result = 0; - - /* loop through each level of the version string */ - while (result == 0) { - /* extract leading version numbers */ - if (kstrtou8(ver1, 10, &num1) < 0) - return -1; + u8 ver1[3], ver2[3]; + int i; - if (kstrtou8(ver2, 10, &num2) < 0) - return -1; + if (sscanf(version1, "%hhu.%hhu.%hhu", + &ver1[0], &ver1[1], &ver1[2]) != 3) + return -1; + if (sscanf(version2, "%hhu.%hhu.%hhu", + &ver2[0], &ver2[1], &ver2[2]) != 3) + return -1; - /* if numbers differ, then set the result */ - if (num1 < num2) - result = -1; - else if (num1 > num2) - result = 1; - else { - /* if numbers are the same, go to next level */ - ver1 = strchr(ver1, '.'); - ver2 = strchr(ver2, '.'); - if (!ver1 && !ver2) - break; - else if (!ver1) - result = -1; - else if (!ver2) - result = 1; - else { - ver1++; - ver2++; - } - } + for (i = 0; i < 3; i++) { + if (ver1[i] > ver2[i]) + return 1; + if (ver1[i] < ver2[i]) + return -1; } - return result; + + return 0; } static int idtcm_xfer_read(struct idtcm *idtcm, -- 2.7.4