From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755123AbcEESaz (ORCPT ); Thu, 5 May 2016 14:30:55 -0400 Received: from e37.co.us.ibm.com ([32.97.110.158]:46049 "EHLO e37.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751844AbcEESay (ORCPT ); Thu, 5 May 2016 14:30:54 -0400 X-IBM-Helo: d03dlp03.boulder.ibm.com X-IBM-MailFrom: arbab@linux.vnet.ibm.com X-IBM-RcptTo: frowand.list@gmail.com;haokexin@gmail.com;robh+dt@kernel.org;grant.likely@linaro.org;devicetree@vger.kernel.org;linux-kernel@vger.kernel.org From: Reza Arbab To: Rob Herring , Frank Rowand , Grant Likely , Kevin Hao , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] of: fix device compatibility scoring Date: Thu, 5 May 2016 13:30:48 -0500 Message-Id: <1462473048-10001-1-git-send-email-arbab@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.3.1 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16050518-0025-0000-0000-00003A1451C5 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If a constraint given to __of_device_is_compatible() does not match, we should just move to the next constraint without adding to the compatibility score. Instead, the function immediately returns 0. Do not return from __of_device_is_compatible() until a complete score has been calculated. Signed-off-by: Reza Arbab --- drivers/of/base.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 017dd94..942a60e 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -455,22 +455,18 @@ static int __of_device_is_compatible(const struct device_node *device, break; } } - if (!score) - return 0; } /* Matching type is better than matching name */ if (type && type[0]) { - if (!device->type || of_node_cmp(type, device->type)) - return 0; - score += 2; + if (device->type && !of_node_cmp(type, device->type)) + score += 2; } /* Matching name is a bit better than not */ if (name && name[0]) { - if (!device->name || of_node_cmp(name, device->name)) - return 0; - score++; + if (device->name && !of_node_cmp(name, device->name)) + score++; } return score; -- 1.8.3.1