From: Al Viro <viro@zeniv.linux.org.uk>
To: Zopolis0 <creatorsmithmdt@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: PATCH [1/2] gamecube/wii: graphic quantization registers driver (GQR)
Date: Sun, 4 Dec 2022 03:36:35 +0000 [thread overview]
Message-ID: <Y4wVwz6kC3ThL2Jg@ZenIV> (raw)
In-Reply-To: <CAEYL+X_X7OsP3BQ3poK4n+DWEOxAais6d9At9nz2TzLFV2HinA@mail.gmail.com>
On Sun, Dec 04, 2022 at 02:06:06PM +1100, Zopolis0 wrote:
> +static u32 gqr_values[8];
> +static struct ctl_table_header *gqr_table_header;
> +
> +#define SPR_GQR0 912
> +#define SPR_GQR1 913
> +#define SPR_GQR2 914
> +#define SPR_GQR3 915
> +#define SPR_GQR4 916
> +#define SPR_GQR5 917
> +#define SPR_GQR6 918
> +#define SPR_GQR7 919
> +
> +#define MFSPR_CASE(i) case (i): (*((u32 *)table->data) = mfspr(SPR_GQR##i))
> +#define MTSPR_CASE(i) case (i): mtspr(SPR_GQR##i, *((u32 *)table->data))
> +
> +static int proc_dogqr(ctl_table *table, int write, struct file *file,
> + void __user *buffer, size_t *lenp, loff_t *ppos)
> +{
> + int r;
> +
> + if (!write) { /* if they are reading, update the variable */
> + switch (table->data - (void *)gqr_values) {
That looks very fishy. First of all, you clearly have table->data set
(by DECLARE_GQR below) to gqr_values + <interger from 0 to 7>. Trivial
C quiz: what would the value of
(void *)(gqr_values + 7) - (void *)gqr_values
be, if gqr_values is declared as an array of unsigned int?
IOW, the values in that switch are wrong. If anything,
you want (u32 *)table->data - gqr_values. What's more, SPR_GQR<n>
is simply 912 + n, innit? So all the crap with switches and ##
is pointless - that thing should simply be
unsigned reg = (u32 *)table->data - gqr_values;
if (WARN_ON_ONCE(reg > 7))
return -EINVAL;
if (!write)
gqr_values[reg] = mfspr(SPR_GQR0 + reg);
r = proc_dointvec(table, write, buffer, lenp, ppos);
if (!r && write) /* if they are writing, update the reg */
mtspr(SPR_GQR0 + reg, gqr_values[reg]);
return r;
prev parent reply other threads:[~2022-12-04 3:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-04 3:06 PATCH [1/2] gamecube/wii: graphic quantization registers driver (GQR) Zopolis0
2022-12-04 3:32 ` Randy Dunlap
2022-12-05 22:14 ` Zopolis0
2022-12-05 22:56 ` Randy Dunlap
2022-12-05 22:15 ` Zopolis0
2022-12-05 23:01 ` Randy Dunlap
2022-12-06 5:20 ` Zopolis0
2022-12-06 5:36 ` Randy Dunlap
2022-12-06 6:01 ` Zopolis0
2022-12-04 3:36 ` Al Viro [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=Y4wVwz6kC3ThL2Jg@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=creatorsmithmdt@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox