From patchwork Wed Sep 10 14:56:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Guido_Mart=C3=ADnez?= X-Patchwork-Id: 387813 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9F04E140170 for ; Thu, 11 Sep 2014 00:58:59 +1000 (EST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XRjKm-0008Ld-HP; Wed, 10 Sep 2014 14:57:24 +0000 Received: from mail-qa0-f50.google.com ([209.85.216.50]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XRjKk-0008HL-Ia for linux-mtd@lists.infradead.org; Wed, 10 Sep 2014 14:57:23 +0000 Received: by mail-qa0-f50.google.com with SMTP id cm18so17111017qab.23 for ; Wed, 10 Sep 2014 07:56:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-type:content-transfer-encoding; bh=d6JRNIWuXepYqfnYM3Sv5NOdbi1PKxONvynWPeq+XvM=; b=DoVo4WYrYSWpk9b+qUe2W3U0WwMB9MOm9ar4sRxEmgXz2pwoC+0k74mO9mpIIS7UnQ hQwakv1zZTVWCkmtWKNzJyJU+L70D3iwtRZSsfQSGpaH8pyDcrqOeL/zfcVkvYy1ILH8 27bF4yVyB6DfWzGOIg7yaOVpqqf8JBw788H6deYDAegWCKmgg6BT/QnBKrGIA7cxtWVB JtgUjw6oibGIVBkpxUoq7hO8Ed5FoLdKUzZ4mXEYlIjt+HH/l0dz43BYONwN3279KEoM FVDbixdpG8dhbfJZgyaQpUzVLcJE7ZH9X6RwcmsUoA64Gdou6S7/B+1WqqBGPOElnjwb Dr8w== X-Gm-Message-State: ALoCoQn7cJ+ioGVXEiFbVR6wPqbaJDgjzSvKhlx51Qik48UygnbgDd8v7MqRwJFxAhs1wLSmJvtV X-Received: by 10.224.24.130 with SMTP id v2mr62064381qab.80.1410361019162; Wed, 10 Sep 2014 07:56:59 -0700 (PDT) Received: from localhost ([181.95.237.187]) by mx.google.com with ESMTPSA id l10sm12995953qai.4.2014.09.10.07.56.57 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Sep 2014 07:56:58 -0700 (PDT) From: =?UTF-8?q?Guido=20Mart=C3=ADnez?= To: linux-mtd@lists.infradead.org, Artem Bityutskiy Subject: [PATCH] libmtd: fix mtd_dev_present return value on legacy systems Date: Wed, 10 Sep 2014 11:56:40 -0300 Message-Id: <1410361000-4821-1-git-send-email-guido@vanguardiasur.com.ar> X-Mailer: git-send-email 2.1.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140910_075722_685447_AA1C5D1F X-CRM114-Status: UNSURE ( 9.74 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.216.50 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.216.50 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Brian Norris , =?UTF-8?q?Ezequiel=20Garc=C3=ADa?= , =?UTF-8?q?Guido=20Mart=C3=ADnez?= X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org On legacy systems, if "/proc/mtd" doesn't exist or gives a read error, mtd_dev_present returns -1 (since it calls legacy_dev_present), contrary to what's specified in the header file. This causes checks like if (mtd_dev_present(n)) { ... } to give false positives. Fix this by comparing the return value to 1. Signed-off-by: Guido Martínez --- lib/libmtd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/libmtd.c b/lib/libmtd.c index 2089373..aff4c8b 100644 --- a/lib/libmtd.c +++ b/lib/libmtd.c @@ -647,9 +647,9 @@ int mtd_dev_present(libmtd_t desc, int mtd_num) { struct stat st; struct libmtd *lib = (struct libmtd *)desc; - if (!lib->sysfs_supported) - return legacy_dev_present(mtd_num); - else { + if (!lib->sysfs_supported) { + return legacy_dev_present(mtd_num) == 1; + } else { char file[strlen(lib->mtd) + 10]; sprintf(file, lib->mtd, mtd_num);