diff --git a/android/abi_gki_aarch64.xml b/android/abi_gki_aarch64.xml index fd29c947a4cb..1f89d3ac2614 100644 --- a/android/abi_gki_aarch64.xml +++ b/android/abi_gki_aarch64.xml @@ -98,6 +98,8 @@ + + @@ -372,6 +374,7 @@ + @@ -497,6 +500,11 @@ + + + + + @@ -643,6 +651,7 @@ + @@ -678,6 +687,7 @@ + @@ -701,6 +711,7 @@ + @@ -1642,6 +1653,7 @@ + @@ -1683,6 +1695,9 @@ + + + @@ -1744,6 +1759,14 @@ + + + + + + + + @@ -1874,6 +1897,7 @@ + @@ -2096,6 +2120,7 @@ + @@ -2285,6 +2310,7 @@ + @@ -2660,6 +2686,7 @@ + @@ -3820,6 +3847,7 @@ + @@ -4366,6 +4394,7 @@ + @@ -4457,6 +4486,7 @@ + @@ -4504,6 +4534,7 @@ + @@ -4559,6 +4590,7 @@ + @@ -4702,7 +4734,7 @@ - + @@ -11465,6 +11497,23 @@ + + + + + + + + + + + + + + + + + @@ -14474,23 +14523,6 @@ - - - - - - - - - - - - - - - - - @@ -14721,6 +14753,16 @@ + + + + + + + + + + @@ -14968,7 +15010,7 @@ - + @@ -17740,6 +17782,7 @@ + @@ -22657,6 +22700,7 @@ + @@ -22980,102 +23024,102 @@ - - + + - - - - - + + + + + - - - - + + + + - - - - - + + + + + - - - - + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - - + + + + - - - - - + + + + + - - - + + + - - - + + + - - - + + + - - - + + + @@ -23873,14 +23917,6 @@ - - - - - - - - @@ -23913,6 +23949,14 @@ + + + + + + + + @@ -25709,7 +25753,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -25723,6 +25804,9 @@ + + + @@ -26883,6 +26967,728 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -26891,6 +27697,11 @@ + + + + + @@ -26907,11 +27718,16 @@ + + + + + @@ -26924,6 +27740,21 @@ + + + + + + + + + + + + + + + @@ -26985,10 +27816,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -27038,6 +27893,20 @@ + + + + + + + + + + + + + + @@ -27101,6 +27970,18 @@ + + + + + + + + + + + + @@ -28503,7 +29384,6 @@ - @@ -28531,6 +29411,9 @@ + + + @@ -37319,6 +38202,8 @@ + + @@ -37786,6 +38671,14 @@ + + + + + + + + @@ -37828,8 +38721,6 @@ - - @@ -39261,13 +40152,13 @@ - + - + @@ -39350,7 +40241,7 @@ - + @@ -39748,7 +40639,7 @@ - + @@ -46157,6 +47048,11 @@ + + + + + @@ -52100,9 +52996,6 @@ - - - @@ -55890,7 +56783,7 @@ - + @@ -55914,7 +56807,7 @@ - + @@ -61914,8 +62807,8 @@ - - + + @@ -88342,7 +89235,7 @@ - + @@ -88568,6 +89461,7 @@ + @@ -88587,7 +89481,7 @@ - + @@ -88766,27 +89660,27 @@ - - + + - + - + - + - + @@ -89510,20 +90404,6 @@ - - - - - - - - - - - - - - @@ -89961,6 +90841,23 @@ + + + + + + + + + + + + + + + + + @@ -90835,23 +91732,6 @@ - - - - - - - - - - - - - - - - - @@ -91725,6 +92605,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -93816,14 +94754,6 @@ - - - - - - - - @@ -94277,6 +95207,7 @@ + @@ -94335,7 +95266,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -103668,23 +104651,6 @@ - - - - - - - - - - - - - - - - - @@ -105070,8 +106036,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -106498,6 +107503,12 @@ + + + + + + @@ -108895,7 +109906,6 @@ - @@ -108921,6 +109931,14 @@ + + + + + + + + @@ -108932,6 +109950,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + @@ -109974,15 +111017,18 @@ - + - + - + - + + + + @@ -109990,7 +111036,7 @@ - + @@ -112303,249 +113349,24 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + + + + - - - - - - - + - - - - - - - - @@ -113770,28 +114591,6 @@ - - - - - - - - - - - - - - - - - - - - - - @@ -115521,92 +116320,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -115685,17 +116398,149 @@ - - - + + + - - + + - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -115755,6 +116600,164 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -115770,6 +116773,11 @@ + + + + + @@ -115777,23 +116785,42 @@ - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + @@ -118110,6 +119137,17 @@ + + + + + + + + + + + @@ -123231,7 +124269,7 @@ - + @@ -123241,22 +124279,6 @@ - - - - - - - - - - - - - - - - @@ -123732,7 +124754,7 @@ - + @@ -123764,7 +124786,7 @@ - + @@ -123772,7 +124794,7 @@ - + @@ -123800,7 +124822,7 @@ - + @@ -124569,7 +125591,7 @@ - + @@ -124590,7 +125612,7 @@ - + @@ -124724,44 +125746,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/android/abi_gki_aarch64_galaxy b/android/abi_gki_aarch64_galaxy index cbe1f884a220..e460d3ff7965 100644 --- a/android/abi_gki_aarch64_galaxy +++ b/android/abi_gki_aarch64_galaxy @@ -161,6 +161,7 @@ __tracepoint_android_vh_is_fpsimd_save __tracepoint_android_vh_kfree_skb __tracepoint_android_vh_ptype_head + __tracepoint_android_vh_wq_lockup_pool __tracepoint_device_pm_callback_end __tracepoint_device_pm_callback_start __tracepoint_gpu_mem_total @@ -2007,6 +2008,7 @@ rtnl_unlock rt_mutex_lock rt_mutex_unlock + runqueues save_stack_trace save_stack_trace_tsk sched_clock @@ -2400,6 +2402,7 @@ trace_raw_output_prep trace_seq_printf tracepoint_probe_register + tracepoint_probe_unregister tracing_off truncate_inode_pages try_module_get diff --git a/android/abi_gki_aarch64_goldfish b/android/abi_gki_aarch64_goldfish index 93efcaf60f8a..3901c3ff26ee 100644 --- a/android/abi_gki_aarch64_goldfish +++ b/android/abi_gki_aarch64_goldfish @@ -15,6 +15,9 @@ blk_queue_write_cache bpf_trace_run2 bpf_trace_run3 + bt_err + bt_info + build_skb cancel_delayed_work_sync cancel_work_sync __cfi_slowpath @@ -37,6 +40,7 @@ _dev_err device_add_disk device_create + device_init_wakeup device_unregister _dev_info __dev_kfree_skb_any @@ -70,8 +74,23 @@ __get_free_pages get_random_bytes get_unused_fd_flags + __hci_cmd_sync + hrtimer_cancel + hrtimer_init + hrtimer_start_range_ns ida_alloc_range ida_free + ieee80211_alloc_hw_nm + ieee80211_beacon_get_tim + ieee80211_csa_finish + ieee80211_csa_is_complete + ieee80211_free_hw + ieee80211_free_txskb + ieee80211_get_tx_rates + ieee80211_iterate_active_interfaces_atomic + ieee80211_register_hw + ieee80211_start_tx_ba_cb_irqsafe + ieee80211_stop_tx_ba_cb_irqsafe init_timer_key init_wait_entry __init_waitqueue_head @@ -84,6 +103,7 @@ jiffies jiffies_to_msecs kfree + kfree_skb kimage_voffset __kmalloc kmalloc_caches @@ -100,6 +120,7 @@ kobject_put kobject_uevent kstrdup + ktime_get ktime_get_mono_fast_ns ktime_get_raw_ts64 ktime_get_real_seconds @@ -123,11 +144,18 @@ mutex_lock_interruptible mutex_trylock mutex_unlock + napi_complete_done + napi_disable + __napi_schedule + napi_schedule_prep netdev_err netdev_info netif_carrier_off netif_carrier_on netif_device_detach + netif_napi_add + netif_set_real_num_rx_queues + netif_set_real_num_tx_queues netif_tx_stop_all_queues netif_tx_wake_queue nf_conntrack_destroy @@ -153,7 +181,6 @@ platform_driver_unregister platform_get_irq platform_get_resource - pm_runtime_allow __pm_runtime_suspend __pm_runtime_use_autosuspend preempt_schedule @@ -184,7 +211,10 @@ register_netdev register_virtio_device register_virtio_driver + __regmap_init + release_firmware remap_pfn_range + request_firmware __request_module request_threaded_irq revalidate_disk @@ -198,7 +228,9 @@ sg_init_one sg_init_table skb_add_rx_frag + skb_page_frag_refill skb_put + skb_to_sgvec snd_card_register snd_ctl_enum_info snd_ctl_sync_vmaster @@ -207,6 +239,7 @@ snd_pcm_add_chmap_ctls snd_pcm_period_elapsed snprintf + softnet_data sort sprintf __stack_chk_fail @@ -248,6 +281,7 @@ virtqueue_detach_unused_buf virtqueue_disable_cb virtqueue_enable_cb + virtqueue_enable_cb_prepare virtqueue_get_avail_addr virtqueue_get_buf virtqueue_get_desc_addr @@ -257,6 +291,7 @@ virtqueue_kick virtqueue_kick_prepare virtqueue_notify + virtqueue_poll vmemmap vring_create_virtqueue vring_del_virtqueue @@ -266,6 +301,63 @@ __wake_up __warn_printk +# required by btintel.ko + bt_to_errno + hci_cmd_sync + request_firmware_direct + +# required by btrtl.ko + bt_warn + +# required by btusb.ko + bit_wait_timeout + btbcm_set_bdaddr + btbcm_setup_apple + btbcm_setup_patchram + device_wakeup_disable + disable_irq + disable_irq_nosync + enable_irq + gpiod_get_optional + gpiod_put + gpiod_set_value_cansleep + hci_alloc_dev + __hci_cmd_sync_ev + hci_free_dev + hci_recv_diag + hci_recv_frame + hci_register_dev + hci_unregister_dev + irq_modify_status + irq_set_irq_wake + of_irq_get_byname + of_match_device + of_property_read_variable_u16_array + out_of_line_wait_on_bit_timeout + pm_system_wakeup + pm_wakeup_dev_event + usb_alloc_urb + usb_anchor_urb + usb_autopm_get_interface + usb_autopm_put_interface + usb_bulk_msg + usb_control_msg + usb_deregister + usb_driver_claim_interface + usb_driver_release_interface + usb_enable_autosuspend + usb_free_urb + usb_get_from_anchor + usb_ifnum_to_if + usb_kill_anchored_urbs + usb_match_id + usb_register_driver + usb_scuttle_anchored_urbs + usb_set_interface + usb_submit_urb + usb_unanchor_urb + wake_up_bit + # required by dummy-cpufreq.ko cpufreq_generic_attr cpufreq_register_driver @@ -283,7 +375,6 @@ # required by goldfish_address_space.ko __ioremap kimage_vaddr - kzfree memremap memunmap @@ -341,7 +432,6 @@ kernel_read kernel_write kern_path - ktime_get lockref_get lock_rename lookup_one_len @@ -398,31 +488,16 @@ genl_notify genl_register_family genl_unregister_family - hrtimer_cancel hrtimer_forward - hrtimer_init - hrtimer_start_range_ns - ieee80211_alloc_hw_nm - ieee80211_beacon_get_tim - ieee80211_csa_finish - ieee80211_csa_is_complete - ieee80211_free_hw - ieee80211_free_txskb - ieee80211_get_tx_rates - ieee80211_iterate_active_interfaces_atomic ieee80211_probereq_get ieee80211_queue_delayed_work ieee80211_ready_on_channel - ieee80211_register_hw ieee80211_remain_on_channel_expired ieee80211_rx_irqsafe ieee80211_scan_completed - ieee80211_start_tx_ba_cb_irqsafe - ieee80211_stop_tx_ba_cb_irqsafe ieee80211_tx_status_irqsafe ieee80211_unregister_hw init_net - kfree_skb kstrndup __netdev_alloc_skb netif_rx @@ -580,7 +655,6 @@ # required by rtc-test.ko add_timer del_timer - device_init_wakeup devm_rtc_allocate_device platform_device_add platform_device_alloc @@ -606,6 +680,7 @@ get_device_system_crosststamp kvasprintf ns_to_timespec + pm_runtime_allow __pm_runtime_disable pm_runtime_enable pm_runtime_forbid @@ -664,7 +739,6 @@ regcache_cache_only regcache_sync regmap_exit - __regmap_init regmap_read regmap_update_bits_base regmap_write @@ -708,6 +782,7 @@ vmalloc # required by virtio-gpu.ko + dma_buf_get_uuid dma_direct_map_sg dma_direct_sync_sg_for_device dma_direct_unmap_sg @@ -769,6 +844,7 @@ drm_gem_object_lookup drm_gem_object_put_unlocked drm_gem_object_release + drm_gem_prime_export drm_gem_prime_fd_to_handle drm_gem_prime_handle_to_fd drm_gem_prime_mmap @@ -809,6 +885,7 @@ ttm_bo_init_mm ttm_bo_kmap ttm_bo_kunmap + ttm_bo_manager_func ttm_bo_mmap ttm_bo_move_to_lru_tail ttm_bo_put @@ -819,6 +896,7 @@ ttm_eu_backoff_reservation ttm_eu_fence_buffer_objects ttm_eu_reserve_buffers + ttm_tt_init ww_mutex_lock_interruptible ww_mutex_unlock @@ -907,7 +985,6 @@ bpf_prog_sub bpf_stats_enabled_key bpf_warn_invalid_xdp_action - build_skb __cpuhp_remove_state __cpuhp_setup_state __cpuhp_state_add_instance @@ -922,21 +999,14 @@ find_next_bit flow_keys_basic_dissector __napi_alloc_skb - napi_complete_done napi_consume_skb - napi_disable napi_gro_receive napi_hash_del - __napi_schedule - napi_schedule_prep netdev_notify_peers netdev_warn netif_device_attach - netif_napi_add netif_napi_del netif_schedule_queue - netif_set_real_num_rx_queues - netif_set_real_num_tx_queues __netif_set_xps_queue net_ratelimit __num_online_cpus @@ -944,18 +1014,13 @@ sched_clock skb_coalesce_rx_frag __skb_flow_dissect - skb_page_frag_refill skb_partial_csum_set - skb_to_sgvec skb_tstamp_tx - softnet_data synchronize_net __tracepoint_xdp_exception virtqueue_add_inbuf_ctx virtqueue_enable_cb_delayed - virtqueue_enable_cb_prepare virtqueue_get_buf_ctx - virtqueue_poll xdp_convert_zc_to_xdp_frame xdp_do_flush_map xdp_do_redirect @@ -985,3 +1050,10 @@ nvdimm_bus_register nvdimm_bus_unregister nvdimm_pmem_region_create + +# required by virtio_wifi.ko + ieee80211_rx_napi + ieee80211_stop_queues + ieee80211_tx_status_ext + ieee80211_wake_queues + init_dummy_netdev diff --git a/android/abi_gki_aarch64_unisoc b/android/abi_gki_aarch64_unisoc index 4266cbe0bcea..e71275e592dd 100644 --- a/android/abi_gki_aarch64_unisoc +++ b/android/abi_gki_aarch64_unisoc @@ -58,6 +58,7 @@ clk_set_parent clk_set_rate clk_unprepare + clocks_calc_mult_shift clockevents_config_and_register __clocksource_register_scale compat_alloc_user_space @@ -72,6 +73,8 @@ cpu_hwcap_keys cpu_hwcaps cpumask_next + cpufreq_add_update_util_hook + cpufreq_remove_update_util_hook cpu_number __cpu_online_mask __cpu_possible_mask @@ -222,7 +225,12 @@ gen_pool_free_owner get_cpu_device __get_free_pages + get_governor_parent_kobj get_random_bytes + gov_attr_set_get + gov_attr_set_init + gov_attr_set_put + governor_sysfs_ops gpiochip_get_data gpiochip_line_is_irq gpiod_direction_input @@ -239,6 +247,7 @@ handle_bad_irq handle_edge_irq handle_level_irq + have_governor_per_policy i2c_del_driver i2c_register_driver i2c_smbus_read_byte_data @@ -311,6 +320,7 @@ irq_of_parse_and_map irq_set_irq_type irq_set_irq_wake + irq_work_sync is_console_locked jiffies jiffies_to_msecs @@ -1419,6 +1429,7 @@ mbox_controller_unregister mbox_free_channel mbox_request_channel + mbox_request_channel_byname mbox_send_message register_syscore_ops @@ -2526,3 +2537,15 @@ snd_pcm_rate_bit_to_rate snd_soc_bytes_info_ext snd_soc_new_compress + +# cpufreq_interactive.ko + add_timer_on + cpufreq_register_notifier + cpufreq_table_index_unsorted + cpufreq_unregister_notifier + down_read_trylock + get_cpu_idle_time + irq_work_queue + kobject_init_and_add + sched_setscheduler_nocheck + strpbrk diff --git a/drivers/base/core.c b/drivers/base/core.c index 81e5265c2cb5..0f9f3701bd89 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1051,10 +1051,8 @@ static ssize_t waiting_for_supplier_show(struct device *dev, bool val; device_lock(dev); - mutex_lock(&wfs_lock); val = !list_empty(&dev->links.needs_suppliers) && dev->links.need_for_probe; - mutex_unlock(&wfs_lock); device_unlock(dev); return sprintf(buf, "%u\n", val); } diff --git a/drivers/usb/gadget/function/f_accessory.c b/drivers/usb/gadget/function/f_accessory.c index 3e0b8b5d7d14..718e01e3190f 100644 --- a/drivers/usb/gadget/function/f_accessory.c +++ b/drivers/usb/gadget/function/f_accessory.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -73,6 +74,7 @@ struct acc_dev { struct usb_function function; struct usb_composite_dev *cdev; spinlock_t lock; + struct acc_dev_ref *ref; struct usb_ep *ep_in; struct usb_ep *ep_out; @@ -80,13 +82,13 @@ struct acc_dev { /* online indicates state of function_set_alt & function_unbind * set to 1 when we connect */ - int online:1; + int online; /* disconnected indicates state of open & release * Set to 1 when we disconnect. * Not cleared until our file is closed. */ - int disconnected:1; + int disconnected; /* strings sent by the host */ char manufacturer[ACC_STRING_SIZE]; @@ -199,14 +201,48 @@ static struct usb_gadget_strings *acc_strings[] = { NULL, }; -/* temporary variable used between acc_open() and acc_gadget_bind() */ -static struct acc_dev *_acc_dev; +struct acc_dev_ref { + struct kref kref; + struct acc_dev *acc_dev; +}; + +static struct acc_dev_ref _acc_dev_ref = { + .kref = KREF_INIT(0), +}; struct acc_instance { struct usb_function_instance func_inst; const char *name; }; +static struct acc_dev *get_acc_dev(void) +{ + struct acc_dev_ref *ref = &_acc_dev_ref; + + return kref_get_unless_zero(&ref->kref) ? ref->acc_dev : NULL; +} + +static void __put_acc_dev(struct kref *kref) +{ + struct acc_dev_ref *ref = container_of(kref, struct acc_dev_ref, kref); + struct acc_dev *dev = ref->acc_dev; + + /* Cancel any async work */ + cancel_delayed_work_sync(&dev->start_work); + cancel_work_sync(&dev->hid_work); + + ref->acc_dev = NULL; + kfree(dev); +} + +static void put_acc_dev(struct acc_dev *dev) +{ + struct acc_dev_ref *ref = dev->ref; + + WARN_ON(ref->acc_dev != dev); + kref_put(&ref->kref, __put_acc_dev); +} + static inline struct acc_dev *func_to_dev(struct usb_function *f) { return container_of(f, struct acc_dev, function); @@ -272,7 +308,10 @@ static void acc_set_disconnected(struct acc_dev *dev) static void acc_complete_in(struct usb_ep *ep, struct usb_request *req) { - struct acc_dev *dev = _acc_dev; + struct acc_dev *dev = get_acc_dev(); + + if (!dev) + return; if (req->status == -ESHUTDOWN) { pr_debug("acc_complete_in set disconnected"); @@ -282,11 +321,15 @@ static void acc_complete_in(struct usb_ep *ep, struct usb_request *req) req_put(dev, &dev->tx_idle, req); wake_up(&dev->write_wq); + put_acc_dev(dev); } static void acc_complete_out(struct usb_ep *ep, struct usb_request *req) { - struct acc_dev *dev = _acc_dev; + struct acc_dev *dev = get_acc_dev(); + + if (!dev) + return; dev->rx_done = 1; if (req->status == -ESHUTDOWN) { @@ -295,6 +338,7 @@ static void acc_complete_out(struct usb_ep *ep, struct usb_request *req) } wake_up(&dev->read_wq); + put_acc_dev(dev); } static void acc_complete_set_string(struct usb_ep *ep, struct usb_request *req) @@ -762,24 +806,36 @@ static long acc_ioctl(struct file *fp, unsigned code, unsigned long value) static int acc_open(struct inode *ip, struct file *fp) { - printk(KERN_INFO "acc_open\n"); - if (atomic_xchg(&_acc_dev->open_excl, 1)) - return -EBUSY; + struct acc_dev *dev = get_acc_dev(); - _acc_dev->disconnected = 0; - fp->private_data = _acc_dev; + if (!dev) + return -ENODEV; + + if (atomic_xchg(&dev->open_excl, 1)) { + put_acc_dev(dev); + return -EBUSY; + } + + dev->disconnected = 0; + fp->private_data = dev; return 0; } static int acc_release(struct inode *ip, struct file *fp) { - printk(KERN_INFO "acc_release\n"); + struct acc_dev *dev = fp->private_data; + + if (!dev) + return -ENOENT; - WARN_ON(!atomic_xchg(&_acc_dev->open_excl, 0)); /* indicate that we are disconnected * still could be online so don't touch online flag */ - _acc_dev->disconnected = 1; + dev->disconnected = 1; + + fp->private_data = NULL; + WARN_ON(!atomic_xchg(&dev->open_excl, 0)); + put_acc_dev(dev); return 0; } @@ -832,7 +888,7 @@ static void acc_complete_setup_noop(struct usb_ep *ep, struct usb_request *req) int acc_ctrlrequest(struct usb_composite_dev *cdev, const struct usb_ctrlrequest *ctrl) { - struct acc_dev *dev = _acc_dev; + struct acc_dev *dev = get_acc_dev(); int value = -EOPNOTSUPP; struct acc_hid_dev *hid; int offset; @@ -843,12 +899,12 @@ int acc_ctrlrequest(struct usb_composite_dev *cdev, u16 w_length = le16_to_cpu(ctrl->wLength); unsigned long flags; -/* - printk(KERN_INFO "acc_ctrlrequest " - "%02x.%02x v%04x i%04x l%u\n", - b_requestType, b_request, - w_value, w_index, w_length); -*/ + /* + * If instance is not created which is the case in power off charging + * mode, dev will be NULL. Hence return error if it is the case. + */ + if (!dev) + return -ENODEV; if (b_requestType == (USB_DIR_OUT | USB_TYPE_VENDOR)) { if (b_request == ACCESSORY_START) { @@ -935,6 +991,7 @@ err: "%02x.%02x v%04x i%04x l%u\n", ctrl->bRequestType, ctrl->bRequest, w_value, w_index, w_length); + put_acc_dev(dev); return value; } EXPORT_SYMBOL_GPL(acc_ctrlrequest); @@ -1005,10 +1062,6 @@ kill_all_hid_devices(struct acc_dev *dev) struct list_head *entry, *temp; unsigned long flags; - /* do nothing if usb accessory device doesn't exist */ - if (!dev) - return; - spin_lock_irqsave(&dev->lock, flags); list_for_each_safe(entry, temp, &dev->hid_list) { hid = list_entry(entry, struct acc_hid_dev, list); @@ -1093,12 +1146,15 @@ static void acc_hid_delete(struct acc_hid_dev *hid) static void acc_hid_work(struct work_struct *data) { - struct acc_dev *dev = _acc_dev; + struct acc_dev *dev = get_acc_dev(); struct list_head *entry, *temp; struct acc_hid_dev *hid; struct list_head new_list, dead_list; unsigned long flags; + if (!dev) + return; + INIT_LIST_HEAD(&new_list); spin_lock_irqsave(&dev->lock, flags); @@ -1144,6 +1200,8 @@ static void acc_hid_work(struct work_struct *data) hid_destroy_device(hid->hid); acc_hid_delete(hid); } + + put_acc_dev(dev); } static int acc_function_set_alt(struct usb_function *f, @@ -1200,9 +1258,13 @@ static void acc_function_disable(struct usb_function *f) static int acc_setup(void) { + struct acc_dev_ref *ref = &_acc_dev_ref; struct acc_dev *dev; int ret; + if (kref_read(&ref->kref)) + return -EBUSY; + dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (!dev) return -ENOMEM; @@ -1218,16 +1280,22 @@ static int acc_setup(void) INIT_DELAYED_WORK(&dev->start_work, acc_start_work); INIT_WORK(&dev->hid_work, acc_hid_work); - /* _acc_dev must be set before calling usb_gadget_register_driver */ - _acc_dev = dev; + dev->ref = ref; + if (cmpxchg_relaxed(&ref->acc_dev, NULL, dev)) { + ret = -EBUSY; + goto err_free_dev; + } ret = misc_register(&acc_device); if (ret) - goto err; + goto err_zap_ptr; + kref_init(&ref->kref); return 0; -err: +err_zap_ptr: + ref->acc_dev = NULL; +err_free_dev: kfree(dev); pr_err("USB accessory gadget driver failed to initialize\n"); return ret; @@ -1235,16 +1303,24 @@ err: void acc_disconnect(void) { + struct acc_dev *dev = get_acc_dev(); + + if (!dev) + return; + /* unregister all HID devices if USB is disconnected */ - kill_all_hid_devices(_acc_dev); + kill_all_hid_devices(dev); + put_acc_dev(dev); } EXPORT_SYMBOL_GPL(acc_disconnect); static void acc_cleanup(void) { + struct acc_dev *dev = get_acc_dev(); + misc_deregister(&acc_device); - kfree(_acc_dev); - _acc_dev = NULL; + put_acc_dev(dev); + put_acc_dev(dev); /* Pairs with kref_init() in acc_setup() */ } static struct acc_instance *to_acc_instance(struct config_item *item) { @@ -1304,7 +1380,6 @@ static void acc_free_inst(struct usb_function_instance *fi) static struct usb_function_instance *acc_alloc_inst(void) { struct acc_instance *fi_acc; - struct acc_dev *dev; int err; fi_acc = kzalloc(sizeof(*fi_acc), GFP_KERNEL); @@ -1316,19 +1391,19 @@ static struct usb_function_instance *acc_alloc_inst(void) err = acc_setup(); if (err) { kfree(fi_acc); - pr_err("Error setting ACCESSORY\n"); return ERR_PTR(err); } config_group_init_type_name(&fi_acc->func_inst.group, "", &acc_func_type); - dev = _acc_dev; return &fi_acc->func_inst; } static void acc_free(struct usb_function *f) { -/*NO-OP: no function specific resource allocation in mtp_alloc*/ + struct acc_dev *dev = func_to_dev(f); + + put_acc_dev(dev); } int acc_ctrlrequest_configfs(struct usb_function *f, @@ -1341,9 +1416,7 @@ int acc_ctrlrequest_configfs(struct usb_function *f, static struct usb_function *acc_alloc(struct usb_function_instance *fi) { - struct acc_dev *dev = _acc_dev; - - pr_info("acc_alloc\n"); + struct acc_dev *dev = get_acc_dev(); dev->function.name = "accessory"; dev->function.strings = acc_strings,