Mpu6050 device improvement and cdev usage - #33
Conversation
|
I have a question: what was the reason for using sysfs kobject? Also have several warnings about format:
|
|
<<< I have a question: what was the reason for using sysfs kobject? |
an1kh
left a comment
There was a problem hiding this comment.
Please fix checkpatch errors (and warnings if possible). e.g:
../../linux/scripts/checkpatch.pl -f *.c
../../linux/scripts/checkpatch.pl -f *.h
Code itself is OK. Please fix format issues and I will have no objections.
|
CS is done |
|
Thank you! Please merge |
AleksandrBulyshchenko
left a comment
There was a problem hiding this comment.
I've made shallow review and haven't tested the solution.
Generally I like the work, which you've done. 👍
The driver looks good despite of unneeded complexity in some parts.
I've commented inline some issues.
And here are some more general notes:
- Implementation of
mpu6050_datamodule looks like example of overengineering for this case:- If you want to create generic collection, it shouldn't use mpu6050-specific types;
- If its the only purpose to store 10 samples from the mpu6050 - it might be much simpler;
- Please use conventional form of tagging commit subjects (
mpu6050: ...in this case); - Also commit messages may be more descriptive;
- And don't forget SOB line;
- 7c095fa ("[Lesson 6] mpu6050 review fix") is empty commit;
IMO at least commit messages and some obvious issues should be fixed before merging.
| struct mpu6050_data_list *element_iter_current; | ||
| struct mpu6050_data_list list; | ||
| }; | ||
|
|
There was a problem hiding this comment.
Please, never ever do like that.
Functions (except inline) mustn’t be defined in header files!
| INDEX_GYRO_Z, | ||
| INDEX_TEMPERATURE, | ||
| INDEX_COUNT, | ||
| /* Another level of data*/ |
There was a problem hiding this comment.
Please avoid mixing indexes of different arrays within the same enum.
The following are not for the data - they are for extra_data and enum should be named accordingly.
|
|
||
| struct cdevs_holder *get_cdevs(void) | ||
| { | ||
| static struct cdevs_holder g_cdevs_holder; |
There was a problem hiding this comment.
Why the driver's static data defined as local variable?
It may have some sense for future compatibility if you're going to expand the driver to support several instances.
But AFAIK this is not the case.
Right now it makes driver understanding and debugging harder with no benefit.
| if (result < 0) | ||
| goto error1; | ||
| cdevs->cdev_full.major = MAJOR(cdevs->cdev_full.dev_no); | ||
| cdevs->cdev_line.read_all = false; |
There was a problem hiding this comment.
Looks like copy-paste error is here.
| struct cdev_instance { | ||
| unsigned int major; | ||
| dev_t dev_no; | ||
| dev_t read_all; |
There was a problem hiding this comment.
The type of read_all seems to be wrong.
| } | ||
|
|
||
| g_reading_thread = kthread_run(reading_thread, NULL, "mpu6050_read_th"); | ||
| if (!g_reading_thread) { |
There was a problem hiding this comment.
Wrong error handling - kthread_run will return negative code in case of errors.
IS_ERR macro should be used for verification.
|
|
||
| if (g_reading_thread) { | ||
| complete(&g_read_comletion); | ||
| kthread_stop(g_reading_thread); |
There was a problem hiding this comment.
It makes sense to set should_stop flag by kthread_stop before waking up the thread by complete.
| kthread_stop(g_reading_thread); | ||
| } | ||
| result = del_timer_sync(&g_read_timer); | ||
| pr_info("mpu6050: timer deleted %d\n", result); |
There was a problem hiding this comment.
Logically timer should be stopped before deleting the thread.
| NULL, | ||
| }; | ||
|
|
||
| /* Gets a number of attributes + 1 (null-terminated) */ |
There was a problem hiding this comment.
In current implementation there's no need in attributes_count() function.
So why not to simplify code a bit?
| /* functionality */ | ||
| static size_t get_attribute_index(struct kobj_attribute const *attribute); | ||
|
|
||
| static int mpu6050_read_data(bool debug) |
There was a problem hiding this comment.
This is definitely wrong way of controlling debug printout.
It should be done on preprocessing stage.
Consider defining macro wrapper over dev_info, which will be expanded to nothing if debug mode not defined.
There was a problem hiding this comment.
That is over-control. It used to allow do not print for any type: or debug, or release
There was a problem hiding this comment.
Renaming the argument to print_out doesn't change anything.
The value provided to it is hardcodded, so there's no sense to keep it as parameter - define should be used instead.
Instead of sysfs class used sysfs kobject. Files-data created at once. Reading of data is done by one function. Controlled resources on initialization failure.
Added functionality to hold 10 last reads of data from mpu6050 device.
Data from device mpu6050 will be read not often than 1 time per second.
Fixed misprint in storing timestamp: it was possibility to store diff of timestamps instead of real value.
Added charetcer-device that allows to read mpu6050-device data in one-line format.
Implementation from header-files (mpu6050_cdev.h, mpu6050_data.h) is moved to source-files.
File with initialization-functions wasn't compiled.
Avoided usage of c++-style comments. Added author.
Added support to dump latest 10 reads from mpu6050 by charecter device.
Structure of data and access to them are incapsulated to allow exclusive access and synchronization.
Added synchronization for data reading/writing.
Timer is added to read data each 1000 msecs.
Code correction according to checkpatch.pl
Cleaned code: avoided unused functions. Added support to read to user buffer with requested size. Corrected misprints for variable types. Divided indexes for different data. Improved module unitialization.
f8d5c26 to
9661f28
Compare
Properly rebased pull-request #29 (up to commit d2f5920).
Improved mpu6050 implementation.
Added storage for 10 latest reads from mpu6050.
Added cdevs to print data in one-line and ten-lines format.
Added timer to read data each 1000 msecs.