From patchwork Thu Jun 12 05:16:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 359024 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7429A1400AB for ; Thu, 12 Jun 2014 17:01:35 +1000 (EST) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by lists.ozlabs.org (Postfix) with ESMTP id 614F51A0338 for ; Thu, 12 Jun 2014 17:01:35 +1000 (EST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org X-Greylist: delayed 6257 seconds by postgrey-1.34 at bilbo; Thu, 12 Jun 2014 17:01:01 EST Received: from mail.windriver.com (mail.windriver.com [147.11.1.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id B23A71A02BD for ; Thu, 12 Jun 2014 17:01:01 +1000 (EST) Received: from ALA-HCB.corp.ad.wrs.com (ala-hcb.corp.ad.wrs.com [147.11.189.41]) by mail.windriver.com (8.14.5/8.14.5) with ESMTP id s5C5GHVB007118 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Wed, 11 Jun 2014 22:16:18 -0700 (PDT) Received: from pek-wyang1-d1.wrs.com (128.224.162.170) by ALA-HCB.corp.ad.wrs.com (147.11.189.41) with Microsoft SMTP Server id 14.3.174.1; Wed, 11 Jun 2014 22:16:17 -0700 From: To: Subject: [PATCH v1] fs2dt: Refine kdump device_tree sort Date: Thu, 12 Jun 2014 13:16:08 +0800 Message-ID: <1402550168-7826-1-git-send-email-Wei.Yang@windriver.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, wei.yang@windriver.com X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Yang Wei The commit b02d735bf was to rearrange the device-tree entries, and assumed that these entries are sorted in the ascending order. but acctually when I was validating kexec and kdump, the order of serial node still is changed. We should not only compare the length of directory name, but also compare the directory name, it would ensure that the order of device node is really in ascending order. Signed-off-by: Yang Wei --- kexec/fs2dt.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) It is validated on Freescale t4240qds. diff --git a/kexec/fs2dt.c b/kexec/fs2dt.c index 1e5f074..0bffaf5 100644 --- a/kexec/fs2dt.c +++ b/kexec/fs2dt.c @@ -479,6 +479,9 @@ static int comparefunc(const struct dirent **dentry1, { char *str1 = (*(struct dirent **)dentry1)->d_name; char *str2 = (*(struct dirent **)dentry2)->d_name; + char* ptr1 = strchr(str1, '@'); + char* ptr2 = strchr(str2, '@'); + int len1, len2; /* * strcmp scans from left to right and fails to idetify for some @@ -486,9 +489,13 @@ static int comparefunc(const struct dirent **dentry1, * Therefore, we get the wrong sorted order like memory@10000000 and * memory@f000000. */ - if (strchr(str1, '@') && strchr(str2, '@') && - (strlen(str1) > strlen(str2))) - return 1; + if (ptr1 && ptr2) { + len1 = ptr1 - str1; + len2 = ptr2 - str2; + if (!strncmp(str1, str2, len1 >len2 ? len1: len2) && + (strlen(str1) > strlen(str2))) + return 1; + } return strcmp(str1, str2); }