Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4302705pxu; Tue, 1 Dec 2020 01:19:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJzlSdwPC4OQ70BaijQkdAqHRJ4ga5kJE3m9tXavExgFV2K7x8/OxUka2ApwU0fzN//AlXIJ X-Received: by 2002:a17:907:216b:: with SMTP id rl11mr2045743ejb.61.1606814387905; Tue, 01 Dec 2020 01:19:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606814387; cv=none; d=google.com; s=arc-20160816; b=mrQ+GEnKF/WITloWKX9bBSPWHxsWO0hbyPNZ3gVhH7Lg4s/xu0whaGEOcO+p+ksZLK Vzt/GqtwVIPepJTUhUHkGdjKk+qkNL2PSETnTpT3VQJaDCdFAskxbqXaRlG8Dl+kdu13 Q9SX90whJM/gtT0dIJdE+HmQlVLzjAZ/CHe7VbayzSxv50NeuhZWJ+PWxOPSYhBMif1b wyBQrSfiB8QSP4iINS1BEr0XiZ4gQyiSOuegzn+MBe4kf7kUQGDneSLDEK8Am2ZH4P/8 ZVWlY8pF6tq2ynnWdMh2Pn+iaD9v3YZ2kc0wHFfIBaPZteGj1qv9XL8UyQ9s4GCyctR7 +tYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YmIp3FO2DjTWeqMoKAagXbclHMyRkOv6waGb0kbC5bY=; b=u1QxSJbsiS+6dwX2nVQjlD8/W/dCFt4NW5gixlRoDTr/D61EM0sRu3ZfDKDelsHu7C UqxxE4zdDNldFPKTuHZcRVz9sb8YfKyJZCnqi5/iwzi0G1rEKkNMa5aG5Uc87xVdPJEf BVWECYXkL0aAMqpSizhDVEZJJOfuh1jv6wop3fXDGIDYrlhohQr8CvpKvGxKKyJnYB3o 5n9xMreuSO3QcipyukOGDnIc4UqSFnASkUDbHavYQ6efL7U4Vk8yZilXZ+BoQBysiEU9 yHoeN6HDrnVf0nIOnRpb7anc/dCEE7/qMVwqBUVY3tNeHT78W34L5sH/XNL0j/BFGk8l Cg8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pisCsEEe; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z16si559428eju.92.2020.12.01.01.19.25; Tue, 01 Dec 2020 01:19:47 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pisCsEEe; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390348AbgLAJOp (ORCPT + 99 others); Tue, 1 Dec 2020 04:14:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:52236 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390162AbgLAJNv (ORCPT ); Tue, 1 Dec 2020 04:13:51 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AFE1021D7A; Tue, 1 Dec 2020 09:13:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606813990; bh=f7LGGGLs+G8aUclUb5lOFtZxAShetPfKAwZ164xh7jY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pisCsEEeSqDFYwhFhK0fPtZ8b4Fps3JC85pCePmgJ6pOSS5v6/af31ZWhN0e2iWbc rQAZiry7DrD+ZFHD0Aab4mv/hd1lHvDU9NwrygzVXKWKX75cm8aAmT48n8R3kJ++Fs PTv1FMRJYO80NIpG1jtFO/krU3U/b1BwNbWGWOl0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Min Li , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.9 128/152] ptp: clockmatrix: bug fix for idtcm_strverscmp Date: Tue, 1 Dec 2020 09:54:03 +0100 Message-Id: <20201201084728.567665251@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084711.707195422@linuxfoundation.org> References: <20201201084711.707195422@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Min Li [ Upstream commit 3cb2e6d92be637b79d6ba0746d610a8dfcc0400b ] 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. Fixes: 7ea5fda2b132 ("ptp: ptp_clockmatrix: update to support 4.8.7 firmware") Signed-off-by: Min Li Link: https://lore.kernel.org/r/1606273115-25792-1-git-send-email-min.li.xe@renesas.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- 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 e020faff7da53..663255774c0b0 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.27.0