Message ID | 20240216225126.454999-1-shresthprasad7@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-69454-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp45077dyc; Fri, 16 Feb 2024 15:16:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVc6LkVv3GHtMMyo3ARJsCBXJuKOVonZaNbHkHT9K0CTDAOsK3hsDNyVHjklPN9db4R/iDu8z6jyW9DdDuSRqiQC2nu3w== X-Google-Smtp-Source: AGHT+IG9Y5JeipyCslfkFiUiK1J0FzXFpG0tU5bBvVIgn0Val5POVYcQPfvbVq93mu8iDK/qHzi4 X-Received: by 2002:a17:902:d504:b0:1da:2390:c6c8 with SMTP id b4-20020a170902d50400b001da2390c6c8mr7892080plg.57.1708125399871; Fri, 16 Feb 2024 15:16:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708125399; cv=pass; d=google.com; s=arc-20160816; b=gygs4Hcag8LBuweMEqCJF7qRE5oapYdt3zZijml+xPdbbCD+0EFjRx9RCjAhDtKlAv RfaPB3Jvp8sG59L3tUW5YtHRE81W1YZ6bGuZiHDfNGLxaTEFQ+S63TgW+HZLasCim2sw ZnKego/9/8tA7DbGQthWw5O7N+DbZxOT2L3X2IYAsli8fWYpq/LmZ/T+EneQHSFPC/mO a4tBEYaziKwUr0Eusq7fvMclzImseuX4+ij2LD+ArIbfbG7ea3ze2c0JgKMfrQs5nQKX Ln+2oXsiwwIR5aib7G9oQ9lb3lw+qSwr4fbZPnf7a38qpwt3MWbB/sYlw58JT5tP/goD sLqQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=fFfXHdvN/5mUfAanVfariAJApfAz/jLdm9t29L3ltRk=; fh=yP8kAcxgzlxeaDiim/Bza/KjlqHHHfjKo23l8g8816c=; b=kx9C9XYK1L4oho3OcPNGJNoNm7DG0FtbC+BXYXFA3UWNd0DKjnSWn3yLBmr3icDV9b zFf/Bl7ls6sntYKReXGdFc0Ipx+z+V825sdpby7vbnogKvs3FvfXdjX55MvOnFlsbrYG WUimp6j8kTo6fDvqAy51LGSlmpBeu7d+m4dfYkIgaa0BUBM2DIMiZ1MKNkH1XJkD55hV 8Ar+Slmm/7EncfjzohVjOGCE3gb0rAe9SY7eNCEd+zMv1F51jb7B9i3k8YD1cCVOPuuQ 4Qb69QRYb7hmlwup5P4gAD7yycgszePcjw4FCcAu/xKFl2IpI30ZAihGkin1ykyG2jU0 Bp+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jsEPWQX+; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-69454-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69454-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id x7-20020a170902a38700b001da2a3e4b27si537245pla.294.2024.02.16.15.16.39 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:16:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69454-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jsEPWQX+; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-69454-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69454-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 2D5E1B26FC8 for <ouuuleilei@gmail.com>; Fri, 16 Feb 2024 22:52:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CC91A1487F0; Fri, 16 Feb 2024 22:51:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jsEPWQX+" Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9224117BC4; Fri, 16 Feb 2024 22:51:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708123901; cv=none; b=aqN70wNqJgP6fvbSsAjVsQfbJl92aKlZr5ro8Lio6Jqa2PYRP61RKUDmske42+uTXfpI6xOM0VascupceMuCb3aB7dzPEscBDA3zHwJFQJJndh5Qm/slE1C6DVE1Av5Xs/tuQNUneviuhqm2aKmytSX31Oiwxw2z8GkC0/YBO2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708123901; c=relaxed/simple; bh=hOmzS5SJMxt/Y5VNiAfAYsPCia8dfM+pw8DUfVZOG/A=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=fQCGtRIswKaTPflwyRzVgimQm5Ye0+aFK3BWpj7lRwtK7oqbbOtsz+CmwYWw3bNV1o8jphSkD2zygnp27JviTV9k56igOLHXyYpMkFJOFLh4Uh1mWg9yLodZjiazGG0Owojpbj8nS+tj5Vfshnzseov4WZ7ILH3BoWfnSIqoyWI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jsEPWQX+; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1d911c2103aso17671735ad.0; Fri, 16 Feb 2024 14:51:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708123899; x=1708728699; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fFfXHdvN/5mUfAanVfariAJApfAz/jLdm9t29L3ltRk=; b=jsEPWQX+1zG/3l+hdyqsgZtnzG6s4hc4+w3OWqqj83q1Su3yQ3nn2ZOhhf5+0clyk4 MXnHZ0uzfQLO8BkNUJC5kscGxM5CphdMxjqsAChinClb0OpoPm0J7Ka4OlOr4q8kPAZZ VxR8Yfj+kQjzVyd4NfgG4unvEwJwxPVBi7FNR9pfQQP4bwiv3UvJAmy6E/KvoXaFFg5t Q1zVrlxBskcI1wK6sIsqQ+zlHMXKyMcaTgO8ztKQZnGxNJp3/HWi5/ZFJWc4/85RwK38 V9i3W3P+ytFtyDJNACmDcQi3PZr2Z04L9/wKC2iF5iLM7+jt8m4m7f2Mr0xg2SeeGTiy kqJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708123899; x=1708728699; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fFfXHdvN/5mUfAanVfariAJApfAz/jLdm9t29L3ltRk=; b=IUXhWqeRBAWhBFumu1XjbfBsv9S8S0cRxm6lS27kVjAez7MnI7Hh3WNGP0BVgzUtI6 EOUzjrxuI6F88DNg9IydOWLNWBHwUCc7Cclre9esFOxaqjqXs9wZwwQQiG8pNLC3hLLV gY5sjMzjAgOjWYJ3rxh3AsfE7WFz3xpCvetCe8vS8JiXitKI0l+3jfTNl8eIcxVqcT09 gkSpsnLurAvQxaIhd3U12Mz7AG1Lyu7/zxbFQAjnU+Z00O2ItQey75pDAN4ZBJGHbSBa eqlgItS1Ga4MJOZYUW9wCW/IiqrAoaUPk6qLXAeP9snL1OaVmCQiJdsVx/KeYDL1B3Jv Lr1Q== X-Forwarded-Encrypted: i=1; AJvYcCVV4wikSIAxyLU2xMCl5ln52sHT8Eqz4yqnxC7zTwub2UL3JNDUYNPZ+6SpCBF7rj53ZtA3dXbFXYjDdtAxeNC4Q+VUWcSAejn1yLTsKcAvV4BgNkLa0Dxmv5Va0hSFT9x8RY+V0rvMQWDnyeLd X-Gm-Message-State: AOJu0Yy7NynWHKfDcj5hSzaf93giElJOm9fI9nIRjUzKlOat1f0CGCL6 czrIz5MeQaokOnqtyW9kFgnMWf/mIb1AxAysKN2x6uI7Rr5H7yX6 X-Received: by 2002:a17:902:bd0a:b0:1d9:4ebd:b94d with SMTP id p10-20020a170902bd0a00b001d94ebdb94dmr6267345pls.55.1708123898663; Fri, 16 Feb 2024 14:51:38 -0800 (PST) Received: from shresth-aspirea71576g.abesec.ac.in ([139.5.197.147]) by smtp.gmail.com with ESMTPSA id a2-20020a170902ee8200b001dbaa8c97e8sm348573pld.225.2024.02.16.14.51.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 14:51:38 -0800 (PST) From: Shresth Prasad <shresthprasad7@gmail.com> To: jpoimboe@kernel.org, jikos@kernel.org, mbenes@suse.cz, pmladek@suse.com, joe.lawrence@redhat.com, shuah@kernel.org Cc: live-patching@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, skhan@linuxfoundation.org, Shresth Prasad <shresthprasad7@gmail.com> Subject: [PATCH] Fix implicit cast warning in test_klp_state.c Date: Sat, 17 Feb 2024 04:21:26 +0530 Message-ID: <20240216225126.454999-1-shresthprasad7@gmail.com> X-Mailer: git-send-email 2.43.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791099299256502117 X-GMAIL-MSGID: 1791099299256502117 |
Series |
Fix implicit cast warning in test_klp_state.c
|
|
Commit Message
Shresth Prasad
Feb. 16, 2024, 10:51 p.m. UTC
The function `klp_get_state` returns an `int` value, but the variable
`loglevel_state` is of type `struct klp_state *` and thus does an
implicit cast. Explicitly casting these values fixes:
- warning: assignment to ‘struct klp_state *’ from ‘int’
makes pointer from integer without a cast [-Wint-conversion]
on lines 38, 55, 68 and 80 of test_klp_state.c
Signed-off-by: Shresth Prasad <shresthprasad7@gmail.com>
---
.../selftests/livepatch/test_modules/test_klp_state.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
Comments
On Sat, 17 Feb 2024 04:21:26 +0530 Shresth Prasad <shresthprasad7@gmail.com> wrote: > The function `klp_get_state` returns an `int` value, but the variable > `loglevel_state` is of type `struct klp_state *` and thus does an > implicit cast. Explicitly casting these values fixes: > > - warning: assignment to \u2018struct klp_state *\u2019 from \u2018int\u2019 > makes pointer from integer without a cast [-Wint-conversion] > > on lines 38, 55, 68 and 80 of test_klp_state.c I was unable to find where you saw the klp_get_state returning int. I tried searching at the current master of live-patching repo[1], on linux-next. Can you point where do you saw it? For me, klp_get_state return a pointer to klp_state. Thanks, Marcos [1]: https://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching.git/tree/kernel/livepatch/state.c > > Signed-off-by: Shresth Prasad <shresthprasad7@gmail.com> > --- > .../selftests/livepatch/test_modules/test_klp_state.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/tools/testing/selftests/livepatch/test_modules/test_klp_state.c b/tools/testing/selftests/livepatch/test_modules/test_klp_state.c > index 57a4253acb01..ae6b1ca15fc0 100644 > --- a/tools/testing/selftests/livepatch/test_modules/test_klp_state.c > +++ b/tools/testing/selftests/livepatch/test_modules/test_klp_state.c > @@ -35,7 +35,7 @@ static int allocate_loglevel_state(void) > { > struct klp_state *loglevel_state; > > - loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); > + loglevel_state = (struct klp_state *)klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); > if (!loglevel_state) > return -EINVAL; > > @@ -52,7 +52,7 @@ static void fix_console_loglevel(void) > { > struct klp_state *loglevel_state; > > - loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); > + loglevel_state = (struct klp_state *)klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); > if (!loglevel_state) > return; > > @@ -65,7 +65,7 @@ static void restore_console_loglevel(void) > { > struct klp_state *loglevel_state; > > - loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); > + loglevel_state = (struct klp_state *)klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); > if (!loglevel_state) > return; > > @@ -77,7 +77,7 @@ static void free_loglevel_state(void) > { > struct klp_state *loglevel_state; > > - loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); > + loglevel_state = (struct klp_state *)klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); > if (!loglevel_state) > return; > > -- > 2.43.1
Well, the repo location I use is git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git. It seem klp_get_state return struct klp_state. The definition of this function in my repo as follows: struct klp_state *klp_get_state(struct klp_patch *patch, unsigned long id) { struct klp_state *state; klp_for_each_state(patch, state) { if (state->id == id) return state; } return NULL; } EXPORT_SYMBOL_GPL(klp_get_state); Are you sure there is really a need for forced conversion? > 2024年2月19日 22:16,Marcos Paulo de Souza <mpdesouza@suse.com> 写道: > > On Sat, 17 Feb 2024 04:21:26 +0530 Shresth Prasad <shresthprasad7@gmail.com> wrote: > >> The function `klp_get_state` returns an `int` value, but the variable >> `loglevel_state` is of type `struct klp_state *` and thus does an >> implicit cast. Explicitly casting these values fixes: >> >> - warning: assignment to \u2018struct klp_state *\u2019 from \u2018int\u2019 >> makes pointer from integer without a cast [-Wint-conversion] >> >> on lines 38, 55, 68 and 80 of test_klp_state.c > > I was unable to find where you saw the klp_get_state returning int. I tried > searching at the current master of live-patching repo[1], on linux-next. Can > you point where do you saw it? For me, klp_get_state return a pointer to klp_state. > > Thanks, > Marcos > > [1]: https://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching.git/tree/kernel/livepatch/state.c > >> >> Signed-off-by: Shresth Prasad <shresthprasad7@gmail.com> >> --- >> .../selftests/livepatch/test_modules/test_klp_state.c | 8 ++++---- >> 1 file changed, 4 insertions(+), 4 deletions(-) >> >> diff --git a/tools/testing/selftests/livepatch/test_modules/test_klp_state.c b/tools/testing/selftests/livepatch/test_modules/test_klp_state.c >> index 57a4253acb01..ae6b1ca15fc0 100644 >> --- a/tools/testing/selftests/livepatch/test_modules/test_klp_state.c >> +++ b/tools/testing/selftests/livepatch/test_modules/test_klp_state.c >> @@ -35,7 +35,7 @@ static int allocate_loglevel_state(void) >> { >> struct klp_state *loglevel_state; >> >> - loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); >> + loglevel_state = (struct klp_state *)klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); >> if (!loglevel_state) >> return -EINVAL; >> >> @@ -52,7 +52,7 @@ static void fix_console_loglevel(void) >> { >> struct klp_state *loglevel_state; >> >> - loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); >> + loglevel_state = (struct klp_state *)klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); >> if (!loglevel_state) >> return; >> >> @@ -65,7 +65,7 @@ static void restore_console_loglevel(void) >> { >> struct klp_state *loglevel_state; >> >> - loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); >> + loglevel_state = (struct klp_state *)klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); >> if (!loglevel_state) >> return; >> >> @@ -77,7 +77,7 @@ static void free_loglevel_state(void) >> { >> struct klp_state *loglevel_state; >> >> - loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); >> + loglevel_state = (struct klp_state *)klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); >> if (!loglevel_state) >> return; >> >> -- >> 2.43.1 >
Looking at the function definition now, I do see that the function returns a struct pointer but for me the compiler still complains about an implicit conversion from int to struct pointer. Is there any particular reason why this might be happening? I couldn't quite figure it out myself as I am very new to working with the kernel. Regards, Shresth
On Tue, 20 Feb 2024 17:23:49 +0530 (GMT+05:30) Shresth Prasad <shresthprasad7@gmail.com> wrote: > Looking at the function definition now, I do see that the function returns a struct pointer but for me the compiler still complains about an implicit conversion from int to struct pointer. > > Is there any particular reason why this might be happening? I couldn't quite figure it out myself as I am very new to working with the kernel. What compiler version and architecture? Are you compiling using flags like W=1? I would advise you to always add more information about how the problem manifests, and what you are executing. This can help to nail down the issue quicker. Thanks, Marcos > > Regards, > Shresth
>What compiler version and architecture? Are you >compiling using flags like W=1? >I would advise you to always add more information >about how the problem >manifests, and what you are executing. This can >help to nail down the issue quicker. I'll keep that in mind. I'm on an x86_64 system with gcc version 13.2.1 20230801. I'm using the command `make -j15 -C tools/testing/selftests` with no additional flags. Regards, Shresth
Would you please pasting the original warning of your complier? And did you check your source code if your source code is the the latest version? Regards, Warden > On Feb 20, 2024, at 21:20, Shresth Prasad <shresthprasad7@gmail.com> wrote: > >> What compiler version and architecture? Are you >compiling using flags like W=1? >> I would advise you to always add more information >about how the problem >> manifests, and what you are executing. This can >help to nail down the issue quicker. > > I'll keep that in mind. I'm on an x86_64 system with gcc version 13.2.1 20230801. > > I'm using the command `make -j15 -C tools/testing/selftests` with no additional flags. > > Regards, > Shresth
I checked the source code and yes I am on the latest Linux next repo. Here's the warning: /home/shresthp/dev/linux_work/linux_next/tools/testing/selftests/livepatch/test_modules/test_klp_state.c:38:24: warning: assignment to ‘struct klp_state *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 38 | loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); | ^ /home/shresthp/dev/linux_work/linux_next/tools/testing/selftests/livepatch/test_modules/test_klp_state.c: In function ‘fix_console_loglevel’: /home/shresthp/dev/linux_work/linux_next/tools/testing/selftests/livepatch/test_modules/test_klp_state.c:55:24: warning: assignment to ‘struct klp_state *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 55 | loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); | ^ /home/shresthp/dev/linux_work/linux_next/tools/testing/selftests/livepatch/test_modules/test_klp_state.c: In function ‘restore_console_loglevel’: /home/shresthp/dev/linux_work/linux_next/tools/testing/selftests/livepatch/test_modules/test_klp_state.c:68:24: warning: assignment to ‘struct klp_state *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 68 | loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); | ^ /home/shresthp/dev/linux_work/linux_next/tools/testing/selftests/livepatch/test_modules/test_klp_state.c: In function ‘free_loglevel_state’: /home/shresthp/dev/linux_work/linux_next/tools/testing/selftests/livepatch/test_modules/test_klp_state.c:80:24: warning: assignment to ‘struct klp_state *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] 80 | loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); | ^ Thank you for your help so far. Regards, Shresth
Shresth Prasad <shresthprasad7@gmail.com> writes: > I checked the source code and yes I am on the latest Linux next repo. > > Here's the warning: > /home/shresthp/dev/linux_work/linux_next/tools/testing/selftests/livepatch/test_modules/test_klp_state.c:38:24: warning: assignment to ‘struct klp_state *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] > 38 | loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); > | ^ Is the declaration of klp_get_state() visible at that point, i.e. is there perhaps any warning about missing declarations above that? Otherwise C rules would default to assume an 'int' return type. Thanks, Nicolai
On 2/21/24 07:44, Nicolai Stange wrote: > Shresth Prasad <shresthprasad7@gmail.com> writes: > >> I checked the source code and yes I am on the latest Linux next repo. >> >> Here's the warning: >> /home/shresthp/dev/linux_work/linux_next/tools/testing/selftests/livepatch/test_modules/test_klp_state.c:38:24: warning: assignment to ‘struct klp_state *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] >> 38 | loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); >> | ^ > > > Is the declaration of klp_get_state() visible at that point, i.e. is > there perhaps any warning about missing declarations above that? > > Otherwise C rules would default to assume an 'int' return type. > This is an interesting clue. I thought I might be able to reproduce the build error by modifying include/livepatch.h and running `make -j15 -C tools/testing/selftests/livepatch` ... but that seemed to work fine on my system. I even removed the entire include/ subdir from my tree and it still built the test module. Huh? Then I moved /lib/modules/$(uname -r)/build out of the way and saw that the compilation failed. Ah hah -- that's right, it's using the system build tree. That version of livepatch.h may have a missing or completely different definition of klp_get_state(). How does this sequence work for you, Shresth: # Verify that kernel livepatching is turned on $ grep LIVEPATCH .config CONFIG_HAVE_LIVEPATCH=y CONFIG_LIVEPATCH=y # Build linux-next kernel tree and then the livepatch selftests, # pointing KDIR to this tree $ make -j$(nproc) vmlinux && \ make -j$(nproc) KDIR=$(pwd) -C tools/testing/selftests/livepatch
diff --git a/tools/testing/selftests/livepatch/test_modules/test_klp_state.c b/tools/testing/selftests/livepatch/test_modules/test_klp_state.c index 57a4253acb01..ae6b1ca15fc0 100644 --- a/tools/testing/selftests/livepatch/test_modules/test_klp_state.c +++ b/tools/testing/selftests/livepatch/test_modules/test_klp_state.c @@ -35,7 +35,7 @@ static int allocate_loglevel_state(void) { struct klp_state *loglevel_state; - loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); + loglevel_state = (struct klp_state *)klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); if (!loglevel_state) return -EINVAL; @@ -52,7 +52,7 @@ static void fix_console_loglevel(void) { struct klp_state *loglevel_state; - loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); + loglevel_state = (struct klp_state *)klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); if (!loglevel_state) return; @@ -65,7 +65,7 @@ static void restore_console_loglevel(void) { struct klp_state *loglevel_state; - loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); + loglevel_state = (struct klp_state *)klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); if (!loglevel_state) return; @@ -77,7 +77,7 @@ static void free_loglevel_state(void) { struct klp_state *loglevel_state; - loglevel_state = klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); + loglevel_state = (struct klp_state *)klp_get_state(&patch, CONSOLE_LOGLEVEL_STATE); if (!loglevel_state) return;