Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5564664ybi; Tue, 28 May 2019 15:25:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqzM0GXRsYQmXOzDw1AWoSaUNGldMkT1Fobaa5NqjWUdZeOKzmc0rkMsUEwgLHTlDFeKoKX7 X-Received: by 2002:a63:2fc3:: with SMTP id v186mr25113609pgv.107.1559082335641; Tue, 28 May 2019 15:25:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559082335; cv=none; d=google.com; s=arc-20160816; b=grk8evzoPXBXaRdnxOTXzqS95QcIoc35xW6gJTiOHZmqDUAWAlAHvt4UhrajvIwYDd quJfVdxb+7u85WuLCB7blz6RORM/KJhuOD7HM5W+HKWJCpE8KfoINxAPJdSJRtBqMrUG thTFl0F7CJMelvs+XNMaCDTdJZk9FkOiiq8S4yBg7UqEqL94FoBxOiIteTuK7zlHIbrj j++8zE2EJ2M33/XMDPw4yzRMWqCe9dEOtixFBADKfw3pLULEQWDVQXTUcg8pbT0b8+oA mYP2ZTfPTDf6zc0TL3y3Wf6GZQTAqtUynWS0tA1X6zVIf7w8zVijSt0pwIY32kj+uM3G 0GlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=kf8jkvG3MlIblfE67W14EXUK2/3Sk/l6QqBEStXLXEE=; b=uhpo1ylxlhtginWW4dzC3lhOJZIwibkos9hAkAsels14kgDxyhZZhfRbNphKHV6+w/ jsyniEa7ehdnB9EDfKzQzgWSER4MOpjwjc7i9a++OdJZTspor8ylarEFdqEIzLMwr1++ rtzsuzBVt8Q+4ffOPfFr1zVBWBEk9Roba56r1d2S6kW6nX69SU+RuvHgklkwwyjSlxKj 45XSrD0hMlJjm+blmWLmZhaKFbMwedGqPL3M2YD9BOnNpmt3jXmfJ84L2rRT+U7bCa6j BtmvMU20wG/r6xrJFhKSzmgkyYXZ0FoD7ofD96U9lteNVkppeiKMr/K1FdoFj5a6pqmQ eWFw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 89si5352848plc.166.2019.05.28.15.25.20; Tue, 28 May 2019 15:25:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726894AbfE1WVX (ORCPT + 99 others); Tue, 28 May 2019 18:21:23 -0400 Received: from mga04.intel.com ([192.55.52.120]:32254 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726492AbfE1WVX (ORCPT ); Tue, 28 May 2019 18:21:23 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 May 2019 15:21:23 -0700 X-ExtLoop1: 1 Received: from ldmartin-desk.jf.intel.com (HELO ldmartin-desk.amr.corp.intel.com) ([10.24.8.221]) by orsmga006.jf.intel.com with ESMTP; 28 May 2019 15:21:22 -0700 Date: Tue, 28 May 2019 15:21:22 -0700 From: Lucas De Marchi To: Bartosz Golaszewski Cc: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: Re: [kmod][PATCH] module: fix error path in kmod_module_probe_insert_module() Message-ID: <20190528222122.f4xswlay47smbvhk@ldmartin-desk.amr.corp.intel.com> References: <20190526092512.993-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20190526092512.993-1-brgl@bgdev.pl> X-Patchwork-Hint: ignore User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 26, 2019 at 11:25:12AM +0200, Bartosz Golaszewski wrote: >From: Bartosz Golaszewski > >The documentation says that kmod_module_probe_insert_module() will >return >0 if "stopped by a reason given in @flags" but it returns a >negative value if KMOD_PROBE_FAIL_ON_LOADED flag is passed and the >relevant module is already loaded. Fix the error path by using a >positive error value where required. > >Signed-off-by: Bartosz Golaszewski >--- > libkmod/libkmod-module.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > >diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c >index bffe715..a3afaba 100644 >--- a/libkmod/libkmod-module.c >+++ b/libkmod/libkmod-module.c >@@ -1253,7 +1253,7 @@ KMOD_EXPORT int kmod_module_probe_insert_module(struct kmod_module *mod, > if (!(flags & KMOD_PROBE_IGNORE_LOADED) > && module_is_inkernel(mod)) { > if (flags & KMOD_PROBE_FAIL_ON_LOADED) >- return -EEXIST; >+ return EEXIST; > else > return 0; > } >@@ -1304,7 +1304,7 @@ KMOD_EXPORT int kmod_module_probe_insert_module(struct kmod_module *mod, > && module_is_inkernel(m)) { > DBG(mod->ctx, "Ignoring module '%s': already loaded\n", > m->name); >- err = -EEXIST; >+ err = EEXIST; this would break the ABI. modprobe for instance, that is in the same repository would be broken by it: kmod_list_foreach() { ... if (err >= 0) /* ignore flag return values such as a mod being blacklisted */ err = 0; else { switch (err) { case -EEXIST: ... } I think we need to say the bug is actually in the bad documentation - my bad actually, on commit b1a51256a9ed ("libkmod-module: probe: change insertion to cover more use cases"). If you look at the definition of 'enum kmod_probe' you will see that not all flags are returned as positive values - the only values that have this behavior are the ones related to blacklist. Could you rather patch the documentation? thanks Lucas De Marchi > goto finish_module; > } > >@@ -1340,14 +1340,14 @@ finish_module: > * been loaded between the check and the moment we try to > * insert it. > */ >- if (err == -EEXIST && m == mod && >+ if (err == EEXIST && m == mod && > (flags & KMOD_PROBE_FAIL_ON_LOADED)) > break; > > /* > * Ignore errors from softdeps > */ >- if (err == -EEXIST || !m->required) >+ if (err == EEXIST || !m->required) > err = 0; > > else if (err < 0) >-- >2.21.0 >