All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Barnabás Pőcze" <pobrn@protonmail.com>
To: jaap aarts <jaap.aarts1@gmail.com>
Cc: Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>,
	"linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Subject: Re: [PATCH V3] hwmon: add fan/pwm driver for corsair h100i platinum
Date: Sat, 15 Aug 2020 18:47:01 +0000	[thread overview]
Message-ID: <92GG6DNvh8x8K43ZGnot6ASLNHBD7l6R6RiI-4jv-Lfki4_tM3IJxPYbp-xajRqMV84Nyw4sp3hZft36ulU2QnxCyhf52kEr6OYe9iujBTk=@protonmail.com> (raw)
In-Reply-To: <CACtzdJ2cPfz7b6bEUsLB5k+JzXFPLLKxxaYRheFPAwV3UQiu5Q@mail.gmail.com>

> [...]
> > > +struct hydro_i_pro_device {
> > > +     struct usb_device *udev;
> > > +
> > > +     const struct device_config *config;
> > > +
> > > +     unsigned char *bulk_out_buffer;
> > > +     char *bulk_in_buffer;
> >
> > Any reason why these two have different sizes? You cast both to
> > 'unsigned char*' in set_fan_target_rpm(), set_fan_pwm_curve(), etc.
>
> I am not sure what you mean by this, I should probably make the type
> consistent between them, is that what you mean by "size"?
>

Oops, yes, I meant type, not size.


> [...]
> > > +struct curve_point {
> > > +     uint8_t temp;
> > > +     uint8_t pwm;
> > > +};
> > > +
> > > +struct hwmon_fan_data {
> > > +     char fan_channel;
> > > +     long fan_target;
> > > +     unsigned char fan_pwm_target;
> >
> > This is very nitpicky, but any reason why is it not 'uint8_t' like above?
> > This applies to other variables as well, I think some variables are too big for what they store,
> > or have a sign, when they could be unsigned.
>
> I moved all the pwm values to u8, and a;ll rpm values to u16(as they
> can't be any bigger)
> I usually don't really write c code, all the different types for the
> same thing confuse me in
> which one to use.
>

Well, I personally try to use unsigned and the smallest integral type
that is acceptable in all the code I write - whenever possible.


> [...]
> > > +static int set_fan_target_pwm(struct hydro_i_pro_device *hdev,
> > > +                           struct hwmon_fan_data *fan_data, long val)
> > > +{
> > > +     int retval;
> > > +     int wrote;
> > > +     int sndpipe = usb_sndbulkpipe(hdev->udev, hdev->bulk_out_endpointAddr);
> > > +     int rcvpipe = usb_rcvbulkpipe(hdev->udev, hdev->bulk_in_endpointAddr);
> > > +
> > > +     unsigned char *send_buf = hdev->bulk_out_buffer;
> > > +     unsigned char *recv_buf = hdev->bulk_in_buffer;
> > > +
> > > +     fan_data->fan_pwm_target = val;
> > > +     fan_data->fan_target = 0;
> > > +
> > > +     send_buf[0] = PWM_FAN_TARGET_CMD;
> > > +     send_buf[1] = fan_data->fan_channel;
> > > +     send_buf[3] = fan_data->fan_pwm_target;
> > > +
> > > +     retval = usb_bulk_msg(hdev->udev, sndpipe, send_buf, 4, &wrote,
> > > +                           BULK_TIMEOUT);
> > > +     if (retval)
> > > +             return retval;
> > > +
> > > +     retval = usb_bulk_msg(hdev->udev, rcvpipe, recv_buf, 6, &wrote,
> > > +                           BULK_TIMEOUT);
> > > +     if (retval)
> > > +             return retval;
> > > +
> > > +     if (!check_succes(send_buf[0], recv_buf)) {
> > > +             dev_info(&hdev->udev->dev,
> > > +                      "[*] failed setting fan pwm %d,%d,%d/%d\n",
> > > +                      recv_buf[0], recv_buf[1], recv_buf[2], recv_buf[3]);
> > > +             return -EINVAL;
> > > +     }
> > > +     return 0;
> > > +}
> > > +
> >
> > The previous four functions are structurally more or less the same,
> > I think the USB related parts could be placed into their own dedicated function.
>
> I could, but the only part that could actually be split up is the usb_bulk_msg.
> If I would remove the error code that part could also be split up.
> Are there any conventions around what to log/not to log? Maybe it is best to
> remove those log messages anyways.
>

What I had in mind was something like this:


// fill send_buf

retval = usb_transaction(...);

if (retval)
	// dev_err(...), etc.

// process recv_buf if necessary


And that function would include the two calls to usb_bulk_msg(), and the
call to check_succes(). You could even write this function in such a way
that all locking is done only in that function minimizing the possibility
of locking related issues. But really, it's up to you.


> [...]
> > > +static void astk_disconnect(struct usb_interface *interface)
> > > +{
> > > +     struct hydro_i_pro_device *hdev = usb_get_intfdata(interface);
> > > +
> > > +     dev_info(&hdev->udev->dev, "[*] DEINIT DEVICE\n");
> >
> > In my opinion the style of the log messages is not consistent,
> > sometimes you use all-caps, sometimes it's all lowercase, sometimes
> > it has punctuation.
>
> Again I couldn't find anything on logging style within the kernel, I am leaning
> towards just removing them all together. If you can find any logging style
> guide link me to it, if not I will just remove all the logs,
>

What I meant is that even in this single module, the style is not consistent.
I don't suggest you get rid of them, just that you use a consistent style.

Another thing, if you want to log a failure, then it should be
dev_err() or dev_warn() depending on the severity - in my opinion.

https://www.kernel.org/doc/html/latest/process/coding-style.html#printing-kernel-messages
talks about kernel messages.


> [...]


Barnabás Pőcze

  reply	other threads:[~2020-08-15 22:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-14 19:42 [PATCH V3] hwmon: add fan/pwm driver for corsair h100i platinum jaap aarts
2020-08-14 23:29 ` Barnabás Pőcze
2020-08-15 12:31   ` jaap aarts
2020-08-15 18:47     ` Barnabás Pőcze [this message]
2020-08-15 20:31       ` jaap aarts
2020-08-15 20:44         ` jaap aarts
2020-08-15 20:52           ` Barnabás Pőcze
2020-08-15 21:00             ` jaap aarts

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='92GG6DNvh8x8K43ZGnot6ASLNHBD7l6R6RiI-4jv-Lfki4_tM3IJxPYbp-xajRqMV84Nyw4sp3hZft36ulU2QnxCyhf52kEr6OYe9iujBTk=@protonmail.com' \
    --to=pobrn@protonmail.com \
    --cc=jaap.aarts1@gmail.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@roeck-us.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.