All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Sabyrzhan Tasbolatov <snovitoll@gmail.com>,
	David Laight <David.Laight@aculab.com>
Cc: gregkh@linuxfoundation.org, andreyknvl@gmail.com, b-liu@ti.com,
	johan@kernel.org, oneukum@suse.com, stern@rowland.harvard.edu,
	linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
	usb-storage@lists.one-eyed-alien.net
Subject: Re: [PATCH v2 0/8] drivers/usb: refactor min/max with min_t/max_t
Date: Sun, 17 Nov 2024 21:55:38 +0200	[thread overview]
Message-ID: <ZzpKOuZeWidsyGis@surfacebook.localdomain> (raw)
In-Reply-To: <20241112155817.3512577-1-snovitoll@gmail.com>

Tue, Nov 12, 2024 at 08:58:09PM +0500, Sabyrzhan Tasbolatov kirjoitti:
> This patch series improves type safety in the drivers/usb/*
> by using `min_t()` and `max_t()` instead of min(), max()
> with the casting inside. It should address potential type promotion issues.
> 
> Scanned the current drivers/usb code with `max\(.*\(` and `min\(.*\(`
> regexp queries to find casting inside of min() and max() which
> may lead to subtle bugs or even security vulnerabilities,
> especially if negative values are involved.
> 
> Let's refactor to min_t() and max_t() specifying the data type
> to ensure it's applicable for the both compareable arguments.

max_t() is okay to use, but min_t() is quite a beast. Please, reconsider the
entire series and tell how had this been tested? I can't imagine how many
subtle bugs it might have introduced.

min_t() explicitly casts to the given type and this is a huge problem for
the cases when one of the parameter is of signed type. Besisdes that it
diminishes the type checking done in the min().

As Linus told, the many cases when you want to have min_t() is actually 
clamp(). In some cases you wanted umin().

+Cc: David.


-- 
With Best Regards,
Andy Shevchenko



      parent reply	other threads:[~2024-11-17 19:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-12 15:04 [PATCH] drivers/usb: refactor min(), max() with min_t(), max_t() Sabyrzhan Tasbolatov
2024-11-12 15:14 ` Greg KH
2024-11-12 15:58   ` [PATCH v2 0/8] drivers/usb: refactor min/max with min_t/max_t Sabyrzhan Tasbolatov
2024-11-12 15:58     ` [PATCH v2 1/8] drivers/usb/gadget: refactor min with min_t Sabyrzhan Tasbolatov
2024-11-12 15:58     ` [PATCH v2 2/8] drivers/usb/core: refactor max with max_t Sabyrzhan Tasbolatov
2024-11-12 15:58     ` [PATCH v2 3/8] drivers/usb/host: refactor min/max with min_t/max_t Sabyrzhan Tasbolatov
2024-11-12 15:58     ` [PATCH v2 4/8] drivers/usb/misc: refactor min with min_t Sabyrzhan Tasbolatov
2024-11-12 15:58     ` [PATCH v2 5/8] drivers/usb/mon: " Sabyrzhan Tasbolatov
2024-11-12 15:58     ` [PATCH v2 6/8] drivers/usb/musb: refactor min/max with min_t/max_t Sabyrzhan Tasbolatov
2024-11-12 15:58     ` [PATCH v2 7/8] drivers/usb/serial: refactor min with min_t Sabyrzhan Tasbolatov
2024-11-12 15:58     ` [PATCH v2 8/8] drivers/usb/storage: " Sabyrzhan Tasbolatov
2024-11-17 19:55     ` Andy Shevchenko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZzpKOuZeWidsyGis@surfacebook.localdomain \
    --to=andy.shevchenko@gmail.com \
    --cc=David.Laight@aculab.com \
    --cc=andreyknvl@gmail.com \
    --cc=b-liu@ti.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=oneukum@suse.com \
    --cc=snovitoll@gmail.com \
    --cc=stern@rowland.harvard.edu \
    --cc=usb-storage@lists.one-eyed-alien.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.