Skip to content

Instantly share code, notes, and snippets.

@Miouyouyou
Last active August 31, 2017 00:01
Show Gist options
  • Save Miouyouyou/52d22a6923d0adbabcfc6950ce2d5fd3 to your computer and use it in GitHub Desktop.
Save Miouyouyou/52d22a6923d0adbabcfc6950ce2d5fd3 to your computer and use it in GitHub Desktop.
Freeze when accessing pdev->resources . This is due to a misuse of %pa . *%pa ARGUMENTS MUST BE PASSED BY REFERENCE*
#ifdef DUMBY_THE_EDITOR /* Used for Kdevelop */
#include <generated/autoconf.h>
#endif
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/of.h>
#include <linux/of_platform.h>
/* Crashes when trying to access pdev->resources[0].
[10731.890314] Name : ff9a0000.vpu-service
[10731.890314] ID : -1
[10731.890314] ID auto : false
[10731.890314] Device (name) : ff9a0000.vpu-service
[10731.890314] Num resources : 3
[10731.890314] Resources address : eea33480
[10731.890314] Platform device ID : (null)
[10731.922220] Printing resources of device
[10731.922223] [0/2] Resource
[10731.930041] Address : eea33480
*/
static inline const char * __restrict myy_bool_str
(bool value)
{
return value ? "true" : "false";
}
/* The freezing part */
static int myy_vpu_probe(struct platform_device * pdev)
{
uint r;
uint n_resources = pdev->num_resources;
uint r_max = n_resources - 1;
/* This parts works nicely */
printk(KERN_INFO
"Name : %s\n"
"ID : %d\n"
"ID auto : %s\n"
"Device (name) : %s\n"
"Num resources : %u\n"
"Resources address : %p\n"
"Platform device ID : %s\n",
pdev->name,
pdev->id,
myy_bool_str(pdev->id_auto),
dev_name(&pdev->dev),
pdev->num_resources,
pdev->resource,
pdev->id_entry->name
);
printk(KERN_INFO "Printing resources of device");
for (r = 0; r < n_resources; r++) {
struct resource const * __restrict const current_res =
&pdev->resource[r];
/* That will be displayed */
printk("[%d/%d] Resource\n", r, r_max);
printk(" Address : %p\n", current_res);
/* Freezes here. Leds stop blinking and all the stuff. */
printk(" Start : %pa\n", current_res->start); /* Stop freezing with &current_res->start */
printk(" End : %pa\n", current_res->end); /* Stop freezing with &current_res->end */
printk(" Name : %s\n", current_res->name);
printk(" Flags : %lx\n", current_res->flags);
printk(" Desc : %lx\n", current_res->desc);
}
return 0;
}
/* Should return 0 on success and a negative errno on failure. */
static int myy_vpu_remove(struct platform_device * pdev)
{
return 0;
}
static void myy_vpu_shutdown(struct platform_device * pdev)
{
printk(KERN_INFO "Shutting down...\n");
}
static const struct of_device_id myy_vpu_dt_ids[] = {
{
.compatible = "rockchip,vpu_service",
},
{}
};
static struct platform_driver myy_vpu_driver = {
.probe = myy_vpu_probe,
.remove = myy_vpu_remove,
.shutdown = myy_vpu_shutdown,
.driver = {
.name = "myy-vpu",
.owner = THIS_MODULE,
.of_match_table = of_match_ptr(myy_vpu_dt_ids),
},
};
module_platform_driver(myy_vpu_driver);
MODULE_LICENSE("GPL v2");
/* Associated DTS : rk3288.dtsi and rk3288-miqi.dts
/ {
...
vpu_service: vpu-service@ff9a0000 {
compatible = "rockchip,vpu_service";
reg = <0xff9a0000 0x800>;
interrupts =
<GIC_SPI 9 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 10 IRQ_TYPE_LEVEL_HIGH>;
interrupt-names = "irq_enc", "irq_dec";
clocks = <&cru ACLK_VCODEC>, <&cru HCLK_VCODEC>;
clock-names = "aclk_vcodec", "hclk_vcodec";
power-domains = <&power RK3288_PD_VIDEO>;
rockchip,grf = <&grf>;
resets = <&cru SRST_VCODEC_AXI>, <&cru SRST_VCODEC_AHB>;
reset-names = "video_a", "video_h";
iommus = <&vpu_mmu>;
iommu_enabled = <1>;
dev_mode = <0>;
status = "okay";
0 means ion, 1 means drm
allocator = <1>;
};
...
}
End of Associated DTS */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment