diff mbox series

[net-next,4/8] libceph: use min() to simplify the code

Message ID 20240822133908.1042240-5-lizetao1@huawei.com (mailing list archive)
State Not Applicable
Delegated to: Netdev Maintainers
Headers show
Series Some modifications to optimize code readability | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 16 this patch: 16
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 16 this patch: 16
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 16 this patch: 16
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-08-25--21-00 (tests: 714)

Commit Message

lizetao Aug. 22, 2024, 1:39 p.m. UTC
When resolving name in ceph_dns_resolve_name(), the end address of name
is determined by the minimum value of delim_p and colon_p. So using min()
here is more in line with the context.

Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
 net/ceph/messenger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Simon Horman Aug. 24, 2024, 6:12 p.m. UTC | #1
On Thu, Aug 22, 2024 at 09:39:04PM +0800, Li Zetao wrote:
> When resolving name in ceph_dns_resolve_name(), the end address of name
> is determined by the minimum value of delim_p and colon_p. So using min()
> here is more in line with the context.
> 
> Signed-off-by: Li Zetao <lizetao1@huawei.com>
> ---
>  net/ceph/messenger.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
> index 3c8b78d9c4d1..d1b5705dc0c6 100644
> --- a/net/ceph/messenger.c
> +++ b/net/ceph/messenger.c
> @@ -1254,7 +1254,7 @@ static int ceph_dns_resolve_name(const char *name, size_t namelen,
>  	colon_p = memchr(name, ':', namelen);
>  
>  	if (delim_p && colon_p)
> -		end = delim_p < colon_p ? delim_p : colon_p;
> +		end = min(delim_p, colon_p);

Both delim_p, and colon_p are char *, so this seems correct to me.

And the code being replaced does appear to be a min() operation in
both form and function.

Reviewed-by: Simon Horman <horms@kernel.org>

However, I don't believe libceph changes usually don't go through next-next.
So I think this either needs to be reposted or get some acks from
one of the maintainers.

Ilya, Xiubo, perhaps you can offer some guidance here?

>  	else if (!delim_p && colon_p)
>  		end = colon_p;
>  	else {
> -- 
> 2.34.1
> 
>
Ilya Dryomov Aug. 25, 2024, 4:21 p.m. UTC | #2
On Sat, Aug 24, 2024 at 8:12 PM Simon Horman <horms@kernel.org> wrote:
>
> On Thu, Aug 22, 2024 at 09:39:04PM +0800, Li Zetao wrote:
> > When resolving name in ceph_dns_resolve_name(), the end address of name
> > is determined by the minimum value of delim_p and colon_p. So using min()
> > here is more in line with the context.
> >
> > Signed-off-by: Li Zetao <lizetao1@huawei.com>
> > ---
> >  net/ceph/messenger.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
> > index 3c8b78d9c4d1..d1b5705dc0c6 100644
> > --- a/net/ceph/messenger.c
> > +++ b/net/ceph/messenger.c
> > @@ -1254,7 +1254,7 @@ static int ceph_dns_resolve_name(const char *name, size_t namelen,
> >       colon_p = memchr(name, ':', namelen);
> >
> >       if (delim_p && colon_p)
> > -             end = delim_p < colon_p ? delim_p : colon_p;
> > +             end = min(delim_p, colon_p);
>
> Both delim_p, and colon_p are char *, so this seems correct to me.
>
> And the code being replaced does appear to be a min() operation in
> both form and function.
>
> Reviewed-by: Simon Horman <horms@kernel.org>
>
> However, I don't believe libceph changes usually don't go through next-next.
> So I think this either needs to be reposted or get some acks from
> one of the maintainers.
>
> Ilya, Xiubo, perhaps you can offer some guidance here?

Hi Simon,

I'm OK with this being taken through net-next.

Acked-by: Ilya Dryomov <idryomov@gmail.com>

Thanks,

                Ilya
Ilya Dryomov Aug. 27, 2024, 7:31 a.m. UTC | #3
On Sun, Aug 25, 2024 at 6:21 PM Ilya Dryomov <idryomov@gmail.com> wrote:
>
> On Sat, Aug 24, 2024 at 8:12 PM Simon Horman <horms@kernel.org> wrote:
> >
> > On Thu, Aug 22, 2024 at 09:39:04PM +0800, Li Zetao wrote:
> > > When resolving name in ceph_dns_resolve_name(), the end address of name
> > > is determined by the minimum value of delim_p and colon_p. So using min()
> > > here is more in line with the context.
> > >
> > > Signed-off-by: Li Zetao <lizetao1@huawei.com>
> > > ---
> > >  net/ceph/messenger.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
> > > index 3c8b78d9c4d1..d1b5705dc0c6 100644
> > > --- a/net/ceph/messenger.c
> > > +++ b/net/ceph/messenger.c
> > > @@ -1254,7 +1254,7 @@ static int ceph_dns_resolve_name(const char *name, size_t namelen,
> > >       colon_p = memchr(name, ':', namelen);
> > >
> > >       if (delim_p && colon_p)
> > > -             end = delim_p < colon_p ? delim_p : colon_p;
> > > +             end = min(delim_p, colon_p);
> >
> > Both delim_p, and colon_p are char *, so this seems correct to me.
> >
> > And the code being replaced does appear to be a min() operation in
> > both form and function.
> >
> > Reviewed-by: Simon Horman <horms@kernel.org>
> >
> > However, I don't believe libceph changes usually don't go through next-next.
> > So I think this either needs to be reposted or get some acks from
> > one of the maintainers.
> >
> > Ilya, Xiubo, perhaps you can offer some guidance here?
>
> Hi Simon,
>
> I'm OK with this being taken through net-next.

I see that Jakub picked up some patches from this series, but not this
one.  I'll go ahead and apply to the Ceph tree.

Thanks,

                Ilya
diff mbox series

Patch

diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index 3c8b78d9c4d1..d1b5705dc0c6 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -1254,7 +1254,7 @@  static int ceph_dns_resolve_name(const char *name, size_t namelen,
 	colon_p = memchr(name, ':', namelen);
 
 	if (delim_p && colon_p)
-		end = delim_p < colon_p ? delim_p : colon_p;
+		end = min(delim_p, colon_p);
 	else if (!delim_p && colon_p)
 		end = colon_p;
 	else {